<template>
  <div class="view-fill">
    <div class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        :title="title"
        :btnList="fullInfo.btnList"
        :needReturn="!flowFormType"
        @returnBack="$emit('returnModify')"
      >
        <template v-slot:full-button>
          <el-button v-if="isShowBatchSave" @click="handleBatchShow()"
            >批量生成</el-button
          >
          <el-button v-if="isShowAddEquipment" @click="addEquipment()"
            >引入资产字典</el-button
          >
        </template>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('basic_information') }}</p>
          </div>
          <div class="model-panel-body">
            <page-form
              class="paddingBox order-model-formBox flex_wrap_start_start"
              v-model:ref-obj="formInfo.baseRef"
              :data="formInfo.data"
              :field-list="formInfo.baseInfoFieldList"
              :rules="formInfo.baseInfoRules"
              :label-width="formInfo.labelWidth"
              :list-type-info="listTypeInfo"
              :image-field="formInfo.imageField"
              @handleEvent="handleEventBaseForm"
            >
              <template v-slot:form-assetFileUrlList>
                <uploadImg
                  v-model:value="formInfo.data.assetFileUrlList"
                  multiple
                  :action="formInfo.imageField.action"
                  title="资产文档"
                  :file-type="formInfo.fileType"
                  :response-fn="handleResponse"
                  :limit="10"
                  :showName="true"
                />
              </template>
              <template v-slot:form-depotName>
                <el-input
                  v-model="formInfo.data.depotName"
                  type="input"
                  :class="
                    canModifyModule ||
                    (buildCardData && buildCardData.length) ||
                    (id &&
                      formInfo.data.orderSourceId &&
                      formInfo.data.orderSourceId !== -2 &&
                      type !== 'create')
                      ? ''
                      : 'not-mongolia'
                  "
                  :disabled="true"
                  placeholder="请选择仓库"
                >
                  <template
                    #append
                    v-if="
                      !(
                        canModifyModule ||
                        (buildCardData && buildCardData.length) ||
                        (id &&
                          formInfo.data.orderSourceId &&
                          formInfo.data.orderSourceId !== -2 &&
                          type !== 'create')
                      )
                    "
                  >
                    <el-icon @click="openDepotWindow"><MoreFilled /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-supplierName>
                <el-input
                  v-if="Number(formInfo.data.temporaryPurch) === 0"
                  type="input"
                  :disabled="true"
                  :class="
                    (buildCardData &&
                      buildCardData.length &&
                      formInfo.data.disabledSupplier) ||
                    (id &&
                      formInfo.data.orderSourceId &&
                      formInfo.data.orderSourceId !== -2 &&
                      type !== 'create' &&
                      !formInfo.data.avaiableEditSupplier)
                      ? ''
                      : 'not-mongolia'
                  "
                  placeholder="请选择供应商"
                  v-model="formInfo.data.supplierName"
                >
                  <template
                    #append
                    v-if="
                      !(
                        (buildCardData &&
                          buildCardData.length &&
                          formInfo.data.disabledSupplier) ||
                        (id &&
                          formInfo.data.orderSourceId &&
                          formInfo.data.orderSourceId !== -2 &&
                          type !== 'create' &&
                          !formInfo.data.avaiableEditSupplier)
                      )
                    "
                  >
                    <el-icon @click="openSupplierWindow"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
                <el-input
                  v-else
                  v-model="formInfo.data.supplierName"
                  placeholder="请选择供应商"
                />
              </template>

              <template v-slot:form-deviceTypeValue>
                <el-input
                  v-model="formInfo.data.deviceTypeValue"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择医疗器械分类目录"
                >
                  <template #append>
                    <el-icon @click="openDeviceTypeWindow"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>

              <!-- <template v-slot:form-useDeptName>
                <el-input
                  v-model="formInfo.data.useDeptName"
                  type="input"
                  :disabled="true"
                  :class="
                    canModifyModule ||
                    (buildCardData && buildCardData.length) ||
                    (id &&
                      formInfo.data.orderSourceId &&
                      formInfo.data.orderSourceId !== -2 &&
                      type !== 'create')
                      ? ''
                      : 'not-mongolia'
                  "
                  placeholder="请选择使用部门"
                >
                  <template
                    #append
                    v-if="
                      !(
                        canModifyModule ||
                        (buildCardData && buildCardData.length) ||
                        (id &&
                          formInfo.data.orderSourceId &&
                          formInfo.data.orderSourceId !== -2 &&
                          type !== 'create')
                      )
                    "
                  >
                    <el-icon @click="openUseDeptWindow"><MoreFilled /></el-icon>
                  </template>
                </el-input>
              </template> -->

              <template v-slot:form-manageDeptName>
                <el-input
                  v-model="formInfo.data.manageDeptName"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择管理部门"
                >
                  <template #append>
                    <el-icon @click="openManageDeptWindow"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-classifyTypeValue>
                <el-input
                  v-model="formInfo.data.classifyTypeValue"
                  :class="canModifyModule ? '' : 'not-mongolia'"
                  type="input"
                  :disabled="true"
                  placeholder="请选择资产分类"
                >
                  <template #append>
                    <el-icon @click="openAssetClassifyWindow"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-financialClassifyTypeValue>
                <el-input
                  v-model="formInfo.data.financialClassifyTypeValue"
                  type="input"
                  :disabled="true"
                  :class="canModifyModule ? '' : 'not-mongolia'"
                  placeholder="请选择资产财务分类"
                >
                  <template #append>
                    <el-icon @click="openFinanceTypeWindow"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-assetUseDeptVOList>
                <el-form
                  :model="formInfo"
                  ref="assetAmortizationDeptTableForm"
                  style="width: 90%"
                >
                  <page-table
                    :refresh="assetAmortizationDeptTableInfo.refresh"
                    :init-curpage="assetAmortizationDeptTableInfo.initCurpage"
                    v-model:data="formInfo.data.assetUseDeptVOList"
                    :api="assetAmortizationDeptTableInfo.api"
                    :pager="false"
                    :check-box="false"
                    :tab-index="true"
                    :query="assetAmortizationDeptTableInfo.query"
                    :field-list="assetAmortizationDeptTableInfo.fieldList"
                    :handle="assetAmortizationDeptTableInfo.handle"
                    @handleEvent="handleEvent"
                  >
                    <template v-slot:col-useDeptName="scope">
                      <el-form-item
                        style="min-width: 100% !important"
                        :prop="`data.assetUseDeptVOList.${scope.$index}.useDeptName`"
                        :rules="
                          scope.$index >= 0
                            ? [
                                {
                                  required:
                                    formInfo.data.isFinanceAsset &&
                                    !(formInfo.data.useStatus == 1)
                                      ? true
                                      : false,
                                  message: '请选择使用部门',
                                  trigger: 'change',
                                },
                              ]
                            : []
                        "
                      >
                        <el-input
                          style="width: 100%"
                          v-model="scope.row.useDeptName"
                          type="input"
                          :disabled="true"
                          :class="canModifyModule ? '' : 'not-mongolia'"
                          placeholder="请选择使用部门"
                        >
                          <template #append>
                            <el-icon @click="openAmortizationDept(scope.$index)"
                              ><MoreFilled
                            /></el-icon>
                          </template>
                        </el-input>
                      </el-form-item>
                    </template>
                    <template v-slot:col-rate="scope">
                      <el-form-item
                        style="min-width: 100% !important"
                        :prop="`data.assetUseDeptVOList.${scope.$index}.rate`"
                        :rules="
                          scope.$index >= 0
                            ? [
                                {
                                  validator: $validate.positiveScore,
                                  trigger: ['blur', 'change'],
                                },
                              ]
                            : []
                        "
                      >
                        <el-input-number
                          style="width: 100%"
                          v-model.lazy="scope.row.rate"
                          clearable
                          controls-position="right"
                          :min="0"
                          :max="100"
                          :precision="2"
                          :disabled="canModifyModule ? true : false"
                        />
                      </el-form-item>
                    </template>
                  </page-table>
                </el-form>
              </template>
              <template v-slot:form-associatedSubcard>
                <!-- //  组件/部件  关联子卡片 -->
                <associatedSubcard
                  ref="associatedSubcardTableForm"
                  :assetResourceVOList="formInfo.data.assetResourceVOList"
                />
              </template>
              <template v-slot:form-assetSubcard>
                <!-- //  组件/部件  关联子卡片 -->
                <assetSubcard
                  :id="id"
                  :type="type"
                  ref="assetSubcardTable"
                  :assetSubcardVOList="formInfo.data.relationAsset"
                />
              </template>
              <template v-slot:form-assetCapitalSourceVOList>
                <el-form
                  :model="formInfo"
                  ref="assetCapitalSourceTableForm"
                  style="width: 100%"
                >
                  <page-table
                    v-model:data="formInfo.data.assetCapitalSourceVOList"
                    :pager="false"
                    :check-box="false"
                    :tab-index="true"
                    :summary="true"
                    :summaryFieldList="
                      assetCapitalSourceTableInfo.summaryFieldList
                    "
                    :field-list="assetCapitalSourceTableInfo.fieldList"
                    :handle="assetCapitalSourceTableInfo.handle"
                  >
                    <template v-slot:col-code="scope">
                      <el-form-item
                        style="min-width: 100% !important"
                        :prop="`data.assetCapitalSourceVOList.${scope.$index}.code`"
                        :rules="
                          scope.$index >= 0
                            ? [
                                {
                                  required: true,
                                  message: '请选择项目类型',
                                  trigger: 'change',
                                },
                              ]
                            : []
                        "
                      >
                        <select-model
                          v-model.lazy="scope.row.code"
                          :type-code="`asset_capital_source`"
                          :disabled="canModifyModule ? true : false"
                          width="100%"
                          @change="changeCapitalSource($event, scope.$index)"
                        />
                      </el-form-item>
                    </template>
                    <template v-slot:col-amount="scope">
                      <el-form-item
                        style="min-width: 100% !important"
                        :prop="`data.assetCapitalSourceVOList.${scope.$index}.amount`"
                        :rules="
                          scope.$index >= 0 && [
                            {
                              validator: $validate.positiveMoneyZeroAsset,
                              trigger: ['blur', 'change'],
                            },
                          ]
                        "
                      >
                        <el-input-number
                          style="width: 100%; display: block"
                          v-model.lazy="scope.row.amount"
                          clearable
                          controls-position="right"
                          :precision="
                            $store.state.permission.systemConfig
                              .assets_price_precision
                          "
                          :min="0"
                          :max="999999999999999"
                          :disabled="canModifyModule ? true : false"
                          @change="changeAmount"
                          @input="
                            changeValidate(
                              $event,
                              `data.assetCapitalSourceVOList.${scope.$index}.amount`,
                              'assetCapitalSourceTableForm'
                            )
                          "
                        />
                      </el-form-item>
                    </template>
                    <template v-slot:col-capitalProjectList="scope">
                      <el-input
                        v-model="scope.row.capitalProjectName"
                        type="input"
                        :disabled="true"
                        :class="
                          canModifyModule &&
                          canModifyModule !== 'noFinanceAsset'
                            ? ''
                            : 'not-mongolia'
                        "
                        placeholder="请选择资金项目"
                      >
                        <template #append>
                          <el-icon
                            @click="openAssetCapitalProjectList(scope.$index)"
                            ><MoreFilled
                          /></el-icon>
                        </template>
                      </el-input>
                    </template>
                  </page-table>
                </el-form>
              </template>
            </page-form>
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('common_information') }}</p>
          </div>
          <div class="model-panel-body">
            <page-form
              class="paddingBox order-model-formBox flex_wrap_start_start"
              v-model:ref-obj="formInfo.commonRef"
              :data="formInfo.data"
              :field-list="formInfo.commonInfoFieldList"
              :rules="formInfo.commonRules"
              :label-width="formInfo.labelWidth"
              :list-type-info="listTypeInfo"
            >
              <template v-slot:form-keeperUserName>
                <el-input
                  v-model="formInfo.data.keeperUserName"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择保管人"
                >
                  <template #append>
                    <el-icon @click="openKeeperUserList"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-acceptanceUserName>
                <el-input
                  v-model="formInfo.data.acceptanceUserName"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择验收人"
                >
                  <template #append>
                    <el-icon @click="openAcceptanceUserList"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-purchUserName>
                <el-input
                  v-model="formInfo.data.purchUserName"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择采购人"
                >
                  <template #append>
                    <el-icon @click="openPurchUserList"><MoreFilled /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-applicationUserName>
                <el-input
                  v-model="formInfo.data.applicationUserName"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择领用人"
                >
                  <template #append>
                    <el-icon @click="openApplicationUserList"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-receiveUserName>
                <el-input
                  v-model="formInfo.data.receiveUserName"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择接收人"
                >
                  <template #append>
                    <el-icon @click="openReceiveUserList"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-useUserName>
                <el-input
                  v-model="formInfo.data.useUserName"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择使用人"
                >
                  <template #append>
                    <el-icon @click="openUseUserList"><MoreFilled /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-responsibleUserName>
                <el-input
                  v-model="formInfo.data.responsibleUserName"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择责任人"
                >
                  <template #append>
                    <el-icon @click="openResponsibleUserList"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
            </page-form>
          </div>
        </div>
        <div
          class="model-panel"
          v-if="formInfo.data.isFinanceAsset == 1 ? true : false"
        >
          <div class="model-panel-title">
            <p>{{ $t('finance_information') }}</p>
          </div>
          <div class="model-panel-body">
            <page-form
              class="paddingBox order-model-formBox flex_wrap_start_start"
              v-model:ref-obj="formInfo.financeRef"
              :data="formInfo.data"
              :field-list="formInfo.financeInfoFieldList"
              :rules="formInfo.financeInfoRules"
              :label-width="formInfo.labelWidth"
              :list-type-info="listTypeInfo"
              @handleEvent="handleEvent"
            >
              <!-- <template v-slot:form-financeDeptName>
                <el-input
                  v-model="formInfo.data.financeDeptName"
                  type="input"
                  :disabled="true"
                  :class="canModifyModule ? '' : 'not-mongolia'"
                  placeholder="请选择财务部门"
                >
                  <template #append>
                    <el-icon @click="openFinanceDeptWindow"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template> -->
              <template v-slot:form-postingDate>
                <el-date-picker
                  v-model="formInfo.data.postingDate"
                  type="date"
                  value-format="YYYY-MM-DD"
                  :disabled="canModifyModule ? true : false"
                  :disabled-date="productionTimePickerOptions.disabledDate"
                  placeholder="选择日期"
                >
                </el-date-picker>
              </template>
              <template v-slot:form-deprMonthsLimit>
                <el-input-number
                  style="width: 40%"
                  v-model.lazy="formInfo.data.deprYearsLimit"
                  clearable
                  :disabled="canModifyModule == 'noFinanceAsset' ? true : false"
                  controls-position="right"
                  :precision="0"
                  :min="0"
                  :max="999999"
                />
                年
                <el-input-number
                  style="width: 40%"
                  v-model.lazy="formInfo.data.deprMonthsLimit"
                  clearable
                  :disabled="canModifyModule == 'noFinanceAsset' ? true : false"
                  controls-position="right"
                  :precision="0"
                  :min="0"
                  :max="12"
                />
                月
              </template>
            </page-form>
          </div>
        </div>
        <div
          class="model-panel"
          v-if="formInfo.data.isMaintenance == 1 ? true : false"
        >
          <div class="model-panel-title">
            <p>{{ $t('maintenance_information') }}</p>
          </div>
          <div class="model-panel-body">
            <page-form
              class="paddingBox order-model-formBox flex_wrap_start_start"
              v-model:ref-obj="formInfo.maintenanceRef"
              :data="formInfo.data"
              :field-list="formInfo.maintenanceInfoFieldList"
              :label-width="formInfo.labelWidth"
              :rules="formInfo.maintenanceInfoRules"
              :list-type-info="listTypeInfo"
              @handleEvent="handleEvent"
            >
              <template v-slot:form-maintenanceProviderName>
                <el-input
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择维保商"
                  v-model="formInfo.data.maintenanceProviderName"
                >
                  <template #append>
                    <el-icon @click="openMaintenanceProviderWindow"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-maintenanceContactsName>
                <el-input
                  v-model="formInfo.data.maintenanceContactsName"
                  type="input"
                  :disabled="true"
                  :class="maintenanceContactsDisabled ? '' : 'not-mongolia'"
                  placeholder="请选择维保商联系人"
                >
                  <template #append>
                    <el-icon @click="openMaintenanceContactsList"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-hospitalMaintainerUserName>
                <el-input
                  v-model="formInfo.data.hospitalMaintainerUserName"
                  type="input"
                  :disabled="true"
                  class="not-mongolia"
                  placeholder="请选择院内维保人"
                >
                  <template #append>
                    <el-icon @click="openHospitalMaintainerUserList"
                      ><MoreFilled
                    /></el-icon>
                  </template>
                </el-input>
              </template>
              <template v-slot:form-repairTime>
                <el-date-picker
                  disabled
                  v-model="formInfo.data.repairTime"
                  type="datetime"
                  format="YYYY-MM-DD HH:mm"
                  value-format="YYYY-MM-DD HH:mm"
                  placeholder="请选择"
                >
                </el-date-picker>
              </template>
              <template v-slot:form-maintenanceTime>
                <el-date-picker
                  disabled
                  v-model="formInfo.data.maintenanceTime"
                  type="datetime"
                  format="YYYY-MM-DD HH:mm"
                  value-format="YYYY-MM-DD HH:mm"
                  placeholder="请选择"
                >
                </el-date-picker>
              </template>
              <template v-slot:form-patrolTime>
                <el-date-picker
                  disabled
                  v-model="formInfo.data.patrolTime"
                  type="datetime"
                  format="YYYY-MM-DD HH:mm"
                  value-format="YYYY-MM-DD HH:mm"
                  placeholder="请选择"
                >
                </el-date-picker>
              </template>
            </page-form>
          </div>
        </div>
        <div
          class="model-panel"
          v-if="formInfo.data.isMetering == 1 ? true : false"
        >
          <div class="model-panel-title">
            <p>{{ $t('measurement_information') }}</p>
          </div>
          <div class="model-panel-body">
            <page-form
              class="paddingBox order-model-formBox flex_wrap_start_start"
              v-model:ref-obj="formInfo.measurementRef"
              :data="formInfo.data"
              :field-list="formInfo.measurementInfoFieldList"
              :label-width="formInfo.labelWidth"
              :rules="formInfo.measurementInfoRules"
              :list-type-info="listTypeInfo"
              @handleEvent="handleEvent"
            >
              <template v-slot:form-verificationDate>
                <el-date-picker
                  v-model="formInfo.data.verificationDate"
                  value-format="YYYY-MM-DD"
                  :disabled-date="checkTimePickerOptions.disabledDate"
                />
              </template>
            </page-form>
          </div>
        </div>
      </NewFullScreen>
    </div>

    <select-dept
      v-if="selectUseDeptInfo.visible"
      v-model:show-dialog="selectUseDeptInfo.visible"
      :query="selectUseDeptInfo.query"
      :check-box="false"
      :highlight-row="true"
      :saveEmpty="true"
      :api="getDeptsSelectPageAndMaintenanceGroup"
      @callback="selectUseDeptCallback"
    />
    <select-dept
      v-if="selectCommonDeptInfo.visible"
      v-model:show-dialog="selectCommonDeptInfo.visible"
      :query="selectCommonDeptInfo.query"
      :check-box="false"
      :saveEmpty="true"
      :highlight-row="true"
      @callback="selectCommonDeptCallback"
    />
    <!-- <select-dept
      v-if="selectFinanceDeptInfo.visible"
      v-model:show-dialog="selectFinanceDeptInfo.visible"
      :query="selectFinanceDeptInfo.query"
      :check-box="false"
      :saveEmpty="true"
      :highlight-row="true"
      @callback="selectFinanceDeptCallback"
    /> -->
    <select-dept
      v-if="addAssetAmortizationDeptInfo.visible"
      v-model:show-dialog="addAssetAmortizationDeptInfo.visible"
      :query="addAssetAmortizationDeptInfo.query"
      :saveEmpty="true"
      :checkBox="false"
      :highlight-row="true"
      @callback="selectAssetAmortizationDeptCallback"
    />
    <select-supplier
      v-if="selectProductSupplier.visible"
      v-model:show-dialog="selectProductSupplier.visible"
      :query="selectProductSupplier.query"
      :check-box="false"
      :saveEmpty="true"
      :highlight-row="true"
      :api="selectProductSupplier.api"
      @callback="selectSupplierCallback"
    />
    <select-maintenance
      v-if="selectMaintenanceProvider.visible"
      v-model:show-dialog="selectMaintenanceProvider.visible"
      :query="selectMaintenanceProvider.query"
      :check-box="false"
      :saveEmpty="true"
      :highlight-row="true"
      @callback="selectMaintenanceProviderCallback"
    />

    <SelectUsers
      v-if="selectKeeperUserInfo.visible"
      v-model:showDialog="selectKeeperUserInfo.visible"
      :query="selectKeeperUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectKeeperUserCallBack"
    />

    <SelectUsers
      v-if="selectAcceptanceUserInfo.visible"
      v-model:showDialog="selectAcceptanceUserInfo.visible"
      :query="selectAcceptanceUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectAcceptanceUserCallBack"
    />
    <SelectUsers
      v-if="selectPurchUserInfo.visible"
      v-model:showDialog="selectPurchUserInfo.visible"
      :query="selectPurchUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectPurchUserCallBack"
    />
    <SelectUsers
      v-if="selectApplicationUserInfo.visible"
      v-model:showDialog="selectApplicationUserInfo.visible"
      :query="selectApplicationUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectApplicationUserCallBack"
    />
    <SelectUsers
      v-if="selectReceiveUserInfo.visible"
      v-model:showDialog="selectReceiveUserInfo.visible"
      :query="selectReceiveUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectReceiveUserCallBack"
    />
    <selectMaintenanceUsers
      v-if="selectMaintenanceContactsInfo.visible"
      v-model:showDialog="selectMaintenanceContactsInfo.visible"
      :saveEmpty="true"
      :api="selectMaintenanceContactsInfo.api"
      :query="selectMaintenanceContactsInfo.query"
      :check-box="false"
      :showPermission="false"
      :highlight-row="true"
      @callback="selectMaintenanceContactsCallBack"
    />
    <selectMaintenanceUsers
      v-if="selectHospitalMaintainerInfo.visible"
      v-model:showDialog="selectHospitalMaintainerInfo.visible"
      :api="selectHospitalMaintainerInfo.api"
      :saveEmpty="true"
      :query="selectHospitalMaintainerInfo.query"
      :check-box="false"
      :highlight-row="true"
      :showPermission="true"
      @callback="selectHospitalMaintainerCallBack"
    />
    <SelectUsers
      v-if="selectUseUserInfo.visible"
      v-model:showDialog="selectUseUserInfo.visible"
      :query="selectUseUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectUseUserCallBack"
    />

    <SelectUsers
      v-if="selectResponsibleUserInfo.visible"
      v-model:showDialog="selectResponsibleUserInfo.visible"
      :query="selectResponsibleUserInfo.query"
      :api="getRrgUserList"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectResponsibleUserCallBack"
    />

    <Select-setting-category
      v-if="selectSettingCategoryInfo.visible"
      v-model:showDialog="selectSettingCategoryInfo.visible"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectSettingCategoryInfoCallBack"
    />

    <SelectSettingClassification
      v-if="selectSettingClassificationInfo.visible"
      v-model:showDialog="selectSettingClassificationInfo.visible"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectSettingClassificationInfoCallBack"
    />
    <!-- 资产弹窗 -->
    <SelectEquipmentArchives
      v-if="equipmentInfo.visible"
      v-model:show-dialog="equipmentInfo.visible"
      :check-box="false"
      :highlight-row="true"
      @callback="changeEquipment"
    />
    <!-- 资产分类 -->
    <SelectAssetClassify
      v-if="selectAssetClassifyInfo.visible"
      v-model:showDialog="selectAssetClassifyInfo.visible"
      :saveEmpty="true"
      :check-box="false"
      :highlight-row="true"
      @callback="selectAssetClassifyInfoCallBack"
    />
    <SelectDepot
      v-if="selectDepotInfo.visible"
      v-model:show-dialog="selectDepotInfo.visible"
      :check-box="false"
      :highlight-row="true"
      :query="selectDepotInfo.query"
      :save-empty="true"
      @callback="selectDepotCallBack"
    />
    <SelectAssetCapitalProject
      v-if="selectAssetCapitalProjectInfo.visible"
      v-model:showDialog="selectAssetCapitalProjectInfo.visible"
      :saveEmpty="true"
      :highlight-row="true"
      :query="selectAssetCapitalProjectInfo.query"
      :queryParams="selectAssetCapitalProjectInfo.queryParams"
      :checkedRowList="selectAssetCapitalProjectInfo.checkedRowList"
      :qty="buildCardCalcQty"
      @callback="selectAssetCapitalProjectCallBack"
    />
    <PageDialog
      v-show="dialogBatchSaveInfo.visible"
      :title="dialogBatchSaveInfo.title"
      v-model:visible="dialogBatchSaveInfo.visible"
      :width="dialogBatchSaveInfo.width"
      :bt-loading="dialogBatchSaveInfo.btLoading"
      :bt-list="dialogBatchSaveInfo.btList"
      @reset="handleClose"
    >
      <page-form
        class="paddingBox order-model-formBox flex_wrap_start_start"
        v-model:ref-obj="formBatchSaveInfo.ref"
        :data="formBatchSaveInfo.data"
        :field-list="formBatchSaveInfo.fieldList"
        :rules="formBatchSaveInfo.rules"
        :label-width="formBatchSaveInfo.labelWidth"
      >
      </page-form>
    </PageDialog>

  </div>
</template>

<script setup name="assetCardModify">
import {
  getCoreCodeStatus,
  getUnitAll,
  createAsset,
  createAssetAndSave,
  submitAssetCardOrder,
  getAssetById,
  getSupplierPage,
  updateAsset,
  updateRecording,
  addByBatchBuildCard,
  checkBuildNumberForAssetCardAndSave,
  getDepotsSelectPageAndMaintenanceGroup,
  getDeptsSelectPageAndMaintenanceGroup,
  getCurrentFiscalPeriod,
} from '@/api/core'
import { getSequence } from '@/api/base'
import utils from '@/common/js/utils' // 公共方法
import { getRrgUserList } from '@/api/base.js'
import { getSelectUserWithPermission } from '@/api/repair.js'
import { getCategoryDetailsById } from '@/api/asset.js'
import SelectAssetCapitalProject from '@/components/SelectAssetCapitalProject/index'
import uploadImg from '@/components/UploadImg/index'
import associatedSubcard from './component/associatedSubcard.vue'
import assetSubcard from './component/assetSubcard.vue'
import selectMaintenanceUsers from '@/components/SelectUsers/selectMaintenanceUsers'
import moment from 'moment'
import axios from 'axios'
import _ from 'lodash'
const { proxy } = getCurrentInstance()
const emits = defineEmits()
const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  isCopy: {
    type: Boolean,
    default: false,
  },
  id: {
    type: [String, Number],
  },
  currentAccountingInterval: {
    type: String,
  },
  canModifyModule: {
    type: String,
    default: '',
  },
  type: {
    type: String,
    default: '',
  },
  buildCardData: {
    type: Array,
    default: function () {
      return []
    },
  },
  title: {
    type: String,
    default: '',
  },
  inventoryLocation: {
    //盘点位置，盘点任务盘盈传过来的
    type: [String, Number],
  },
  fillData: {
    type: Array,
    default: () => {
      return []
    },
  },
  flowFormType: {
    type: String,
    default: '',
  },
})
let validateDeprMonthsLimit = (rule, value, callback) => {
  let deprMonthsLimit =
    (formInfo.value.data.deprYearsLimit || 0) * 12 +
    (formInfo.value.data.deprMonthsLimit || 0)
  if (value === '') {
    callback(new Error('请输入折旧月限'))
  } else {
    if (formInfo.value.data.monthsUsed !== '') {
      if (deprMonthsLimit < formInfo.value.data.monthsUsed) {
        callback(new Error('输入的折旧月限不能小于已使用月数!'))
      } else {
        callback()
      }
    }
    callback()
  }
}
let validateMonthsUsed = (rule, value, callback) => {
  let deprMonthsLimit =
    (formInfo.value.data.deprYearsLimit || 0) * 12 +
    (formInfo.value.data.deprMonthsLimit || 0)
  console.log(deprMonthsLimit)
  if (value === '' || value == undefined) {
    callback(new Error('请输入已使用月数'))
  } else if (
    deprMonthsLimit < value &&
    formInfo.value.data.deprMethodType != '0'
  ) {
    callback(new Error('输入的已使用月数不能大于折旧月限!'))
  } else {
    const reg = /^(0|[1-9][0-9]*)$/
    if (!reg.test(value) && formInfo.value.data.deprMethodType != '0') {
      callback(new Error('输入大于等于0的整数'))
    } else {
      callback()
    }
  }
}
let validateResidualAmount = (rule, value, callback) => {
  let originalAmount = formInfo.value.data.originalAmount
    ? formInfo.value.data.originalAmount
    : 0
  if (value === '' || value == undefined) {
    callback(new Error('请输入0~999999999999999的数字'))
  } else if (originalAmount < value) {
    callback(new Error('输入的残值不能大于原值!'))
  } else {
    callback()
  }
}
let validateDeprPreparation = (rule, value, callback) => {
  let originalAmount = formInfo.value.data.originalAmount
    ? formInfo.value.data.originalAmount
    : 0
  if (value === '' || value == undefined) {
    callback()
  } else if (originalAmount < value) {
    callback(new Error('输入的减值准备不能大于原值!'))
  } else {
    callback()
  }
}
let validateSumDeprAmount = (rule, value, callback) => {
  let originalAmount = formInfo.value.data.originalAmount
    ? formInfo.value.data.originalAmount
    : 0
  if (value === '' || value == undefined) {
    callback(new Error('请输入0~999999999999999的数字'))
  } else if (originalAmount < value) {
    callback(new Error('输入的累计折旧不能大于原值!'))
  } else {
    callback()
  }
}
const checkTimePickerOptions = ref({
  disabledDate: (time) => {
    return time.getTime() > Date.now() - 8.64e6
  },
})
const isShowAddEquipment = ref(false)
// 批量生成
const isShowBatchSave = ref(false)
const dialogBatchSaveInfo = reactive({
  visible: false,
  title: '批量生成',
  btLoading: false,
  row: {},
  width: '400px',
  btList: [
    {
      label: '关闭',
      event: handleClose,
      show: true,
    },
    {
      label: '保存',
      type: 'primary',
      event: handleBatchSave,
      show: true,
    },
    {
      label: '保存并提交',
      type: 'primary',
      event: handleBatchSaveAndSubmit,
      show: true,
    },
  ],
})
const formBatchSaveInfo = reactive({
  data: {
    countNum: '',
  },
  fieldList: [
    {
      label: '任务拆分类型',
      value: 'countNum',
      type: 'number',
      min: 1,
      max: 100,
      precision: 0,
    }
  ],
  labelWidth: '120px',
})

const productionTimePickerOptions = ref({})
const selectProductSupplier = ref({
  visible: false,
  api: getSupplierPage,
  query: {
    supplierAuth: 'supplierId',
  },
})
const selectMaintenanceProvider = ref({
  visible: false,
  query: {},
})
const selectDepotInfo = ref({
  visible: false,
  query: {
    depotAuth: 'id',
    status: 1,
    useTypeId: 2,
  },
})
const selectKeeperUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectAcceptanceUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectPurchUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectApplicationUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectReceiveUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectMaintenanceContactsInfo = ref({
  visible: false,
  saveEmpty: true,
  api: getSelectUserWithPermission,
  query: {
    orgId: '',
    assetId: '',
    deptId: '',
    depotId: '',
    assetClassifyId: '',
  },
})
const selectHospitalMaintainerInfo = ref({
  visible: false,
  saveEmpty: true,
  api: getSelectUserWithPermission,
  query: {
    orgId: '',
    assetId: '',
    deptId: '',
    depotId: '',
    assetClassifyId: '',
  },
})
const selectUseUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectSettingClassificationInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {},
})
const selectSettingCategoryInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {},
})
const selectAssetCapitalProjectInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {},
  checkedRowList: [],
  queryParams: {
    assetId: null,
  },
})
const selectResponsibleUserInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {
    hasAllDept: 1,
  },
})
const selectUseDeptInfo = ref({
  visible: false,
  query: {
    deptAuth: 'id',
  },
})
const selectCommonDeptInfo = ref({
  visible: false,
  query: {
    deptAuth: 'id',
  },
})
// const selectFinanceDeptInfo = ref({
//   visible: false,
//   query: {
//     deptAuth: 'id',
//   },
// })
const selectAssetClassifyInfo = ref({
  visible: false,
  saveEmpty: true,
  query: {},
})
const addAssetAmortizationDeptInfo = ref({
  visible: false,
  query: {
    deptAuth: 'id',
    idNotIn: '',
  },
})

const formInfo = ref({
  baseRef: null,
  commonRef: null,
  financeRef: null,
  maintenanceRef: null,
  measurementRef: null,
  data: {
    originalAmount: 0,
    // accrualMark: 1,
    monthsUsed: 0,
    residualRate: 0,
    sumDeprAmount: 0,
    deprMonthsLimit: 0,
    deprYearsLimit: 0,
    isFinanceAsset:
      proxy.$store.state.permission.systemConfig.is_finance_asset_strategy,
    isMaintenance:
      proxy.$store.state.permission.systemConfig.is_maintenance_strategy,
    isMetering: proxy.$store.state.permission.systemConfig.is_metering_strategy,
    assetUseDeptVOList: [{ useDeptName: '' }],
    assetCapitalSourceVOList: [{ code: '', amount: 0 }],
    qty: 1,
    inputTax: 0,
    residualAmount: 0,
    monthDeprRate: 0,
    postingDate: moment(new Date()).format('YYYY-MM-DD'),

    price: 0,
    installCost: 0,
    transportCost: 0,
    taxCost: 0,
  },
  formDisabled: false,
  delFiledList: [],
  fileType: ['png', 'jpg', 'jpeg', 'pdf', 'doc', 'docx'],
  imageField: {
    label: '资产图片',
    value: 'fileUrlList',
    action: axios.defaults.baseURL + '/pub/uploadfile',
    multipleSheets: true,
    listType: 'text',
    limit: 10,
    multiple: false,
    fileType: ['png', 'jpg', 'jpeg', 'gif'],
  },
  fieldUploadList: [
    {
      label: '资产图片',
      value: 'fileUrlList',
      type: 'slot',
      className: 'not-br',
    },
  ],
  baseInfoFieldList: [
    {
      label: '资产名称',
      value: 'assetName',
      type: 'input',
      required: true,
      maxlength: 100,
      disabled: false,
    },
    {
      label: '资产卡片号',
      value: 'assetCode',
      type: 'input',
      show: false,
      required: true,
    },
    {
      label: '规格',
      value: 'standard',
      type: 'input',
      maxlength: 100,
    },
    {
      label: '厂家名称',
      value: 'brandName',
      type: 'input',
      maxlength: 100,
    },
    {
      label: '品牌',
      value: 'mark',
      type: 'input',
      maxlength: 100,
    },
    {
      label: '医疗器械分类目录',
      value: 'deviceTypeValue',
      type: 'slot',
    },
    {
      label: '医疗器械管理类别',
      value: 'deviceTypeCategory',
      type: 'select-model',
      code: 'device_type_category',
      checkDefault: false,
      clearable: true,
    },
    {
      label: '临时采购',
      value: 'temporaryPurch',
      type: 'select-model',
      clearable: true,
      code: 'default_no_or_yes',
      event: 'temporaryPurch',
      disabled: false,
    },
    {
      label: '供应商',
      value: 'supplierName',
      type: 'slot',
      required: false,
    },
    {
      label: '产地',
      value: 'originPlace',
      type: 'input',
    },

    {
      label: '使用状态',
      value: 'useStatus',
      type: 'select-model',
      code: 'asset_use_status',
      onlyShowOption: ['1', '2'],
      disabled: false,
      // optionDisabled: ["3", "4", "5", "6", "7", "8", "9", "10", "11"],
      required: true,
      event: 'useStatus',
    },
    // {
    //   label: '计提标志',
    //   value: 'accrualMark',
    //   type: 'select-model',
    //   clearable: true,
    //   code: 'accrual_mark',
    //   required: true,
    //   disabled: true,
    // },
    // {
    //   label: '使用部门',
    //   value: 'useDeptName',
    //   type: 'slot',
    //   required: true,
    //   show: false,
    // },
    {
      label: '仓库',
      value: 'depotName',
      type: 'slot',
      required: true,
      show: true,
    },
    {
      label: '管理部门',
      value: 'manageDeptName',
      type: 'slot',
      required: true,
    },
    {
      label: '增加方式',
      value: 'increaseType',
      type: 'select-model',
      // clearable: true,
      code: 'increase_type',
      required: true,
      disabled: false,
    },
    {
      label: '计量单位',
      value: 'unitId',
      type: 'select',
      clearable: true,
      list: 'unitList',
      filterable: true,
      required:
        proxy.$store.state.permission.systemConfig.asset_unit_necessarily == '1'
          ? true
          : false,
    },
    {
      label: '数量',
      value: 'qty',
      type: 'number',
      max: 99999999,
      disabled: true,
      // formatter: proxy.$fn.TripartiteMethodAsset,
    },
    {
      label: '资产单价',
      value: 'price',
      type: 'number',
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      required: true,
      event: 'primitiveOriginalAmountSetValue',
      disabled:
        props.buildCardData && props.buildCardData.length ? true : false,
    },
    {
      label: '安装费',
      value: 'installCost',
      type: 'number',
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      required: true,
      event: 'primitiveOriginalAmountSetValue',
      disabled:
        props.buildCardData && props.buildCardData.length ? true : false,
    },
    {
      label: '运杂费',
      value: 'transportCost',
      type: 'number',
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      required: true,
      event: 'primitiveOriginalAmountSetValue',
      disabled:
        props.buildCardData && props.buildCardData.length ? true : false,
    },
    {
      label: '税费',
      value: 'taxCost',
      type: 'number',
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      required: true,
      event: 'primitiveOriginalAmountSetValue',
      disabled:
        props.buildCardData && props.buildCardData.length ? true : false,
    },
    {
      label: '原值',
      value: 'primitiveOriginalAmount',
      type: 'number',
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      required: true,
      event: 'primitiveOriginalAmount',
      disabled: true,
      // props.buildCardData && props.buildCardData.length ? true : false,
    },
    {
      label: '资产分类',
      value: 'classifyTypeValue',
      type: 'slot',
      required: true,
    },
    {
      label: '资产类型',
      value: 'assetType',
      type: 'select-model',
      clearable: true,
      code: 'asset_type',
      required: true,
      disabled: true,
    },
    {
      label: '资产财务分类',
      value: 'financialClassifyTypeValue',
      required:
        proxy.$store.state.permission.systemConfig.is_finance_asset_strategy,
      type: 'slot',
    },
    {
      label: '设备标识',
      value: 'assetMark',
      type: 'select-model',
      clearable: true,
      multiple: true,
      code: 'assets_mark',
    },

    {
      label: '是否为财务资产',
      value: 'isFinanceAsset',
      type: 'radio-model',
      code: 'yes_or_no',
      // disabled: true,
      // show: proxy.$permission("assetCard:financeAsset"),
    },
    {
      label: '是否维保',
      value: 'isMaintenance',
      type: 'radio-model',
      code: 'yes_or_no',
      // show: proxy.$permission("assetCard:maintenance"),
    },
    {
      label: '是否为计量资产',
      value: 'isMetering',
      type: 'radio-model',
      code: 'yes_or_no',
      // show: proxy.$permission("assetCard:metering"),
    },
    {
      label: '是否医疗设备',
      value: 'isMedicalEquipment',
      type: 'radio-model',
      code: 'default_no_or_yes',
    },
    {
      label: '报修预警时长(分钟)',
      value: 'repairWarnTime',
      labelTip:
        '该设备报修后超过设置分钟调度人员仍未派单则系统将自动通知调度员派单',
      type: 'number',
    },
    {
      label: '使用部门',
      value: 'assetUseDeptVOList',
      type: 'slot',
      className: 'not-br',
    },
    {
      label: '资金来源',
      value: 'assetCapitalSourceVOList',
      type: 'slot',
      className: 'not-br',
      required: true,
    },
    {
      label: '组件/部件',
      value: 'associatedSubcard',
      type: 'slot',
      className: 'not-br',
      labelTip: '必须填了组件名称和数量才算一条有效的组件/部件',
    },
    {
      label: '关联子卡片',
      value: 'assetSubcard',
      type: 'slot',
      show: props.type !== 'buildCard',
      className: 'not-br',
    },
    {
      label: '备注',
      value: 'remark',
      type: 'textarea',
      className: 'not-br',
    },
    {
      label: '资产文档',
      value: 'assetFileUrlList',
      type: 'slot',
      className: 'not-br',
    },
  ],
  commonInfoFieldList: [
    {
      label: 'SN',
      value: 'machineCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '注册证号',
      value: 'registerCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '合同号',
      value: 'contractCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '档案号',
      value: 'fileCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '发票编号',
      value: 'invoiceCode',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '批号',
      value: 'batchNumber',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '出厂日期',
      value: 'manufactureDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '生产日期',
      value: 'productionDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '安装日期',
      value: 'installDate',
      type: 'date',
      placeholder: false,
    },
    // {
    //   label: "启用日期",
    //   value: "enableDate",
    //   type: "date",
    //   placeholder: false,
    // },
    {
      label: '验收人',
      value: 'acceptanceUserName',
      type: 'slot',
    },
    {
      label: '验收日期',
      value: 'acceptanceDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '采购人',
      value: 'purchUserName',
      type: 'slot',
    },
    {
      label: '采购日期',
      value: 'purchDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '入库日期',
      value: 'storeDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '开始使用日期',
      value: 'useDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '领用人',
      value: 'applicationUserName',
      type: 'slot',
    },
    {
      label: '领用日期',
      value: 'applicationDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '保管人',
      value: 'keeperUserName',
      type: 'slot',
    },
    {
      label: '使用人',
      value: 'useUserName',
      type: 'slot',
    },
    {
      label: '责任人',
      value: 'responsibleUserName',
      type: 'slot',
    },

    {
      label: '接收人',
      value: 'receiveUserName',
      type: 'slot',
    },
    {
      label: '预算号',
      value: 'budgetNo',
      type: 'input',
      maxlength: 150,
    },
    {
      label: '申购论证号',
      value: 'applicationNo',
      type: 'input',
      maxlength: 150,
    },
    {
      label: '合同号',
      value: 'contractNo',
      type: 'input',
      maxlength: 150,
    },
    {
      label: '存放地点',
      value: 'location',
      type: 'textarea',
      maxlength: 150,
    },
    {
      label: '使用年限',
      value: 'useYear',
      type: 'number',
      min: 1,
      max: 999,
    },
    {
      label: '采购类型',
      value: 'purchType',
      type: 'select-model',
      clearable: true,
      code: 'asset_purch_type',
    },
  ],
  financeInfoFieldList: [
    // {
    //   label: '财务部门',
    //   value: 'financeDeptName',
    //   type: 'slot',
    // },

    {
      label: '原值',
      value: 'originalAmount',
      type: 'number',
      required: true,
      placeholder: false,
      disabled: true,
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
    },
    {
      label: '净值',
      value: 'netAmount',
      type: 'number',
      placeholder: false,
      disabled: true,
      max: 999999999999999,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      labelTip: '计算方法： <br/>' + '原值-累计折旧-减值准备',
    },
    // {
    //   label: '残值',
    //   value: 'residualAmount',
    //   type: 'number',
    //   required: true,
    //   placeholder: false,
    //   formatter: proxy.$fn.TripartiteMethodAsset,
    //   precision:
    //     proxy.$store.state.permission.systemConfig.assets_price_precision,
    //   max: 999999999999999,
    //   event: 'residualAmount',
    // },
    // {
    //   label: '残值率(%)',
    //   value: 'residualRate',
    //   type: 'number',
    //   required: true,
    //   placeholder: false,
    //   formatter: proxy.$fn.TripartiteMethodAsset,
    //   precision:
    //     proxy.$store.state.permission.systemConfig.assets_price_precision,
    //   max: 100,
    //   event: 'residualRate',
    // },
    // {
    //   label: '折旧月限',
    //   value: 'deprMonthsLimit',
    //   type: 'number',
    //   required: true,
    //   placeholder: false,
    //   max: 99999999,
    //   show: true,
    // },
    {
      label: '折旧月限',
      value: 'deprMonthsLimit',
      type: 'slot',
      show: true,
    },
    {
      label: '已使用月数',
      value: 'monthsUsed',
      type: 'number',
      // required: true,
      placeholder: false,
      max: 99999999,
      show: true,
    },
    {
      label: '减值准备',
      value: 'deprPreparation',
      type: 'number',
      placeholder: false,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      max: 999999999999999,
      show: true,
    },
    {
      label: '累计折旧',
      value: 'sumDeprAmount',
      type: 'number',
      required: true,
      placeholder: false,
      formatter: proxy.$fn.TripartiteMethodAsset,
      precision:
        proxy.$store.state.permission.systemConfig.assets_price_precision,
      max: 999999999999999,
      show: true,
    },
    {
      label: '折旧方法',
      value: 'deprMethodType',
      type: 'select-model',
      clearable: true,
      code: 'depr_method_type',
      required: true,
      show: true,
    },
    {
      label: '折旧惯例',
      value: 'deprConvention',
      type: 'select-model',
      clearable: true,
      code: 'depr_convention',
      required: true,
      // disabled: true,
      show: true,
    },
    // {
    //   label: '进项税',
    //   value: 'inputTax',
    //   type: 'number',
    //   placeholder: false,
    //   formatter: proxy.$fn.TripartiteMethodAsset,
    //   precision:
    //     proxy.$store.state.permission.systemConfig.assets_price_precision,
    //   max: 999999999999999,
    //   show: true,
    // },
    {
      label: '入账日期',
      value: 'postingDate',
      type: 'slot',
      show: true,
    },
    {
      label: '财政资产编码',
      value: 'financialAssetCode',
      type: 'input',
    },
    // {
    //   label: '月折旧率(%)',
    //   value: 'monthDeprRate',
    //   type: 'number',
    //   formatter: proxy.$fn.TripartiteMethodAsset,
    //   disabled: true,
    //   precision:
    //     proxy.$store.state.permission.systemConfig.assets_price_precision,
    //   max: 100,
    //   labelTip: '平均折旧法 <br/>' + '月折旧率(%)： 1/折旧月限*100<br/>',
    //   show: true,
    // },
    // {
    //   label: '月折旧额',
    //   value: 'monthDeprAmount',
    //   type: 'number',
    //   formatter: proxy.$fn.TripartiteMethodAsset,
    //   disabled: true,
    //   precision:
    //     proxy.$store.state.permission.systemConfig.assets_price_precision,
    //   max: 999999999999999,
    //   labelTip: '平均折旧法 <br/>' + '月折旧额： (原值-减值准备)*月折旧率<br/>',
    //   show: true,
    // },
  ],
  maintenanceInfoFieldList: [
    {
      label: '保修类型',
      value: 'warrantyType',
      type: 'select-model',
      clearable: true,
      code: 'warranty_type',
    },
    {
      label: '保修状态',
      value: 'warrantyStatus',
      type: 'select-model',
      clearable: true,
      code: 'warranty_status',
    },
    {
      label: '维保商',
      value: 'maintenanceProviderName',
      type: 'slot',
    },
    {
      label: '维保商联系人',
      value: 'maintenanceContactsName',
      type: 'slot',
    },
    {
      label: '维保商联系人电话',
      value: 'maintenancePhone',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '院内维保人',
      value: 'hospitalMaintainerUserName',
      type: 'slot',
    },
    {
      label: '院内维保人电话',
      value: 'hospitalMaintainerPhone',
      type: 'input',
      maxlength: 32,
    },
    {
      label: '维保开始日期',
      value: 'warrantyStartDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '维保结束日期',
      value: 'warrantyEndDate',
      type: 'date',
      placeholder: false,
    },
    {
      label: '维保合同编号',
      value: 'maintenanceContract',
      type: 'input',
    },
    {
      label: '维保说明',
      value: 'maintenanceDescription',
      type: 'textarea',
      maxlength: 200,
    },
    {
      label: '维修状态',
      value: 'repairStatus',
      type: 'select-model',
      clearable: true,
      disabled: true,
      code: 'asset_repair_status',
    },
    {
      label: '报修日期',
      value: 'repairTime',
      type: 'slot',
      disabled: true,
      placeholder: false,
    },
    {
      label: '最近养护日期',
      value: 'maintenanceTime',
      type: 'slot',
      disabled: true,
      placeholder: false,
    },
    {
      label: '最近巡检日期',
      value: 'patrolTime',
      type: 'slot',
      disabled: true,
      placeholder: false,
    },
  ],
  measurementInfoFieldList: [
    {
      label: '标准名称',
      value: 'measurementName',
      type: 'input',
    },
    {
      label: '专业分类',
      value: 'professionalClassification',
      type: 'select-model',
      clearable: true,
      code: 'professional_classification',
    },
    {
      label: '是否强检',
      value: 'isMandatoryInspection',
      type: 'select-model',
      clearable: true,
      code: 'yes_or_no',
    },
    {
      label: '拼音码',
      value: 'pinyinCode',
      type: 'input',
    },
    {
      label: '测量范围',
      value: 'measurementRange',
      type: 'input',
    },
    {
      label: '准确度',
      value: 'accuracy',
      type: 'input',
    },
    {
      label: '检定周期(月)',
      value: 'verificationPeriod',
      type: 'number',
      min: 0,
      max: 9999,
    },
    {
      label: '检定类型',
      value: 'verificationType',
      type: 'select-model',
      clearable: true,
      code: 'verification_type',
    },
    {
      label: '检定单位',
      value: 'verificationUnit',
      type: 'input',
    },
    {
      label: '主要参数',
      value: 'mainParameter',
      type: 'input',
    },
    {
      label: '上次检定日期',
      value: 'verificationDate',
      type: 'slot',
      placeholder: false,
    },
    {
      label: '下次检定日期',
      value: 'validityDate',
      type: 'date',
      placeholder: false,
      disabled: true,
      required: true,
    },
    {
      label: '最新检定结果',
      value: 'verificationResult',
      type: 'select-model',
      clearable: true,
      code: 'verification_result',
    },

    {
      label: '检定证书编号',
      value: 'verificationCertificateNumber',
      type: 'input',
    },

  ],
  baseInfoRules: {
    supplierName: [
      {
        required: false,
        message: '请输入供应商',
        trigger: 'blur',
      },
    ],
  },
  financeInfoRules: {
    // accrualMark: [
    //   {
    //     required: true,
    //     message: '请选择计提标志',
    //     trigger: 'change',
    //   },
    // ],
    originalAmount: [
      {
        required: true,
        message: '请输入0~999999999999999的数字',
        trigger: 'blur',
      },
      {
        validator: proxy.$validate.positiveAssetMoneyZero,
        trigger: 'blur',
      },
    ],
    // residualAmount: [
    //   {
    //     required: true,
    //     validator: validateResidualAmount,
    //     trigger: 'blur',
    //   },
    //   {
    //     validator: proxy.$validate.positiveAssetMoneyZero,
    //     trigger: 'blur',
    //   },
    // ],
    deprMonthsLimit: [
      {
        required: true,
        validator: validateDeprMonthsLimit,
        trigger: 'blur',
      },
      {
        validator: proxy.$validate.positiveAssetMoneyZero,
        trigger: 'blur',
      },
    ],
    deprPreparation: [
      {
        validator: validateDeprPreparation,
        trigger: 'blur',
      },
    ],
    // residualRate: [
    //   {
    //     required: true,
    //     message: '请输入0~100的数字',
    //     trigger: 'blur',
    //   },
    //   {
    //     validator: proxy.$validate.positiveAssetMoneyZero,
    //     trigger: 'blur',
    //   },
    // ],
    monthsUsed: [
      {
        // required: true,
        validator: validateMonthsUsed,
        trigger: 'blur',
      },
    ],
    sumDeprAmount: [
      {
        required: true,
        validator: validateSumDeprAmount,
        trigger: 'blur',
      },
      {
        validator: proxy.$validate.positiveAssetMoneyZero,
        trigger: 'blur',
      },
    ],
    deprMethodType: [
      {
        required: true,
        message: '请选择折旧方法',
        trigger: 'blur',
      },
    ],
    deprConvention: [
      {
        required: true,
        message: '请选择折旧惯例',
        trigger: 'blur',
      },
    ],
    postingDate: [
      {
        required: true,
        message: '请输入入账日期',
        trigger: 'blur',
      },
    ],
  },
  measurementInfoRules: {
    // verificationPeriod: [
    //   {
    //     required: true,
    //     validator: proxy.$validate.naturalnumber,
    //     trigger: 'blur',
    //   },
    // ],
    // verificationDate: [
    //   {
    //     required: true,
    //     message: '请选择检定日期',
    //     trigger: 'change',
    //   },
    // ],
  },
  labelWidth: '130px',
})
const listTypeInfo = ref({
  licenseList: [],
  brandList: [],
  unitList: [],
})
const fullInfo = ref({
  btnList: [
    {
      label: '保存并提交',
      event: saveAndSubmit,
      show:
        props.type !== 'update' &&
        proxy.$permission('assetCard:saveAndSubmit') &&
        !props.flowFormType,
    },
    { label: '保存', event: save, show: !props.flowFormType },
  ],
})
const equipmentInfo = ref({
  visible: false,
  query: {
    status: 1,
  },
})
//资金来源表格
const assetCapitalSourceTableInfo = ref({
  data: [],
  summaryFieldList: [
    { value: 'amount', formatter: proxy.$fn.TripartiteMethodAsset },
  ],
  fieldList: [
    {
      label: '项目类型',
      value: 'code',
      type: 'slot',
    },
    {
      label: '金额',
      value: 'amount',
      type: 'slot',
    },
    {
      label: '资金项目',
      value: 'capitalProjectList',
      type: 'slot',
    },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '新增行',
        event: addSource,
        show: true,
      },
      {
        label: '删除',
        event: removeSource,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: true,
        ifRender: ifRenderRemoveSource,
      },
    ],
  },
})
//使用部门表格
const assetAmortizationDeptTableInfo = ref({
  data: [],
  fieldList: [
    {
      label: '使用部门',
      value: 'useDeptName',
      type: 'slot',
    },
    {
      label: '占比(%)',
      value: 'rate',
      type: 'slot',
      labelTip: '总值100%',
    },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '新增行',
        event: addDept,
        show: true,
      },
      {
        label: '清空',
        event: clearDept,
        popconfirmText: '清空后将改变数据,是否继续？',
        show: true,
        ifRender: ifRenderClearDept,
      },
      {
        label: '删除',
        event: removeDept,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: true,
        ifRender: ifRenderRemoveDept,
      },
    ],
  },
})
const flag = ref(true)
const maintenanceContactsDisabled = ref(true) //维保商联系人是否不可编辑
const addAssetAmortizationDeptIndex = ref(null)
const changeAmountFlag = ref(false)
const changeUseDeptNameFlag = ref(false)
const assetAmortizationDeptTableForm = ref(null)
const assetCapitalSourceTableForm = ref(null)
const formRefs = ref(null)
const buildCardCalcQty = ref(0)
const currentAccountingIntervalIsFlow = ref('')

const showDialog = computed({
  get() {
    return props.visible
  },
  set(val) {
    // 更新父组件visible
    emits('update:visible', val)
  },
})
// watch(
//   () => formInfo.value.data.accrualMark,
//   (val) => {
//     //计提标志

//     if (
//       formInfo.value.data.isFinanceAsset &&
//       !(
//         formInfo.value.data.useStatus == 1 &&
//         formInfo.value.data.accrualMark == 1
//       )
//     ) {
//       formInfo.value.baseInfoRules.assetUseDeptVOList = [
//         {
//           required: true,
//         },
//       ]
//     } else {
//       formInfo.value.baseInfoRules.assetUseDeptVOList = [
//         {
//           required: false,
//         },
//       ]

//       if (assetAmortizationDeptTableForm.value) {
//         assetAmortizationDeptTableForm.value.clearValidate()
//       }
//     }
//   }
// )
watch(
  () => formInfo.value.data.useStatus,
  (val) => {
    if (Number(val) === 1) {
      //待领用
      if (
        props.canModifyModule !== 'noFinanceAsset' &&
        props.type !== 'createSurplus'
      ) {
        showFieldListItem(true, 'depotName')
        // showFieldListItem(false, 'useDeptName')
      }

      if (!props.canModifyModule) {
        formInfo.value.baseInfoFieldList.forEach((item) => {
          // if (item.value === 'accrualMark') {
          //   item.disabled = false
          //   if (props.type === 'createSurplus') {
          //     item.disabled = true
          //   }
          // }
        })
      }
    } else if (Number(val) === 2) {
      //正常使用
      if (
        props.canModifyModule !== 'noFinanceAsset' &&
        props.type !== 'createSurplus'
      ) {
        showFieldListItem(false, 'depotName')
        // showFieldListItem(true, 'useDeptName')
      }

      // if (flag.value) {
      //   formInfo.value.data.accrualMark = 0
      // }
      // if (!props.canModifyModule) {
      //   formInfo.value.baseInfoFieldList.forEach((item) => {
      //     if (item.value === 'accrualMark') {
      //       item.disabled = true
      //     }
      //   })
      // }
    }
    // if (props.canModifyModule && formInfo.value.data.assetStatus === 3) {
    //   formInfo.value.baseInfoFieldList.forEach((item) => {
    //     if (item.value === 'accrualMark') {
    //       item.disabled = false
    //       if (props.type === 'createSurplus') {
    //         item.disabled = true
    //       }
    //     }
    //   })
    // }
    if (
      formInfo.value.data.isFinanceAsset &&
      !(formInfo.value.data.useStatus == 1)
    ) {
      // formInfo.value.baseInfoRules.assetUseDeptVOList = [
      //   {
      //     required: true,
      //   },
      // ]
    } else {
      // formInfo.value.baseInfoRules.assetUseDeptVOList = [
      //   {
      //     required: false,
      //   },
      // ]

      if (assetAmortizationDeptTableForm.value) {
        assetAmortizationDeptTableForm.value.clearValidate()
      }
    }
  }
)

watch(
  () => props.buildCardData,
  (val) => {
    proxy.$nextTick(() => {
      if (val && val.length) {
        buildCardCalcQty.value = 0
        val.forEach((item) => {
          buildCardCalcQty.value = proxy.$fn.accAdd(
            item.buildCardCalcQty || 0,
            buildCardCalcQty.value
          )
        })
        let copyArr = proxy.$fn.deepClone(val)
        formInfo.value.baseInfoFieldList.forEach((item) => {
          if (item.value === 'useStatus' || item.value === 'assetName') {
            item.disabled = true
          }
        })
        //没有供应商的可以修改，有供应商的不可修改
        if (val[0].supplierName) {
          formInfo.value.data.disabledSupplier = true
          formInfo.value.baseInfoFieldList.forEach((item) => {
            if (item.value === 'temporaryPurch') {
              item.disabled = true
            }
          })
        } else {
          formInfo.value.data.disabledSupplier = false
          formInfo.value.baseInfoFieldList.forEach((item) => {
            if (item.value === 'temporaryPurch') {
              item.disabled = false
            }
          })
        }
        if (val[0].increaseType !== 0 || !val[0].increaseType) {
          //收货
          proxy.$nextTick(() => {
            formInfo.value.data.useStatus = 2
            showFieldListItem(false, 'depotName')
            // showFieldListItem(true, 'useDeptName')
          })

          // formInfo.value.baseInfoFieldList.forEach((item) => {
          //   if (item.value === 'accrualMark') {
          //     item.disabled = true
          //   }
          // })
          if (val.length > 1) {
            let uniqArr = _.uniqBy(copyArr, 'deptName')
            if (val.length !== uniqArr.length) {
              formInfo.value.data.manageDeptName = val[0].deptName
              formInfo.value.data.manageDeptId = val[0].deptId
              // formInfo.value.data.useDeptId = val[0].deptId
              // formInfo.value.data.useDeptName = val[0].deptName
            }
          } else {
            formInfo.value.data.manageDeptName = val[0].deptName
            formInfo.value.data.manageDeptId = val[0].deptId
            // formInfo.value.data.useDeptId = val[0].deptId
            // formInfo.value.data.useDeptName = val[0].deptName
          }
        }
        if (val[0].increaseType === 0 || val[0].increaseType) {
          //入库

          proxy.$nextTick(() => {
            formInfo.value.data.useStatus = 1
            showFieldListItem(true, 'depotName')
            // showFieldListItem(false, 'useDeptName')
          })

          // formInfo.value.baseInfoFieldList.forEach((item) => {
          //   if (item.value === 'accrualMark') {
          //     item.disabled = false
          //   }
          // })
          if (val.length > 1) {
            let uniqArr = _.uniqBy(copyArr, 'depotName')
            if (val.length !== uniqArr.length) {
              formInfo.value.data.depotName = val[0].depotName
              formInfo.value.data.depotId = val[0].depotId
            }
          } else {
            formInfo.value.data.depotName = val[0].depotName
            formInfo.value.data.depotId = val[0].depotId
          }
        }

        formInfo.value.data.postingDate = moment(new Date()).format(
          'YYYY-MM-DD'
        )
        formInfo.value.data.assetName = val[0].commonName
        formInfo.value.data.classifyTypeValue = val[0].assetTypeValue
        formInfo.value.data.classifyType = val[0].assetType
        formInfo.value.data.standard = val[0].standard
        formInfo.value.data.brandName = val[0].brandName
        formInfo.value.data.mark = val[0].trademark
        formInfo.value.data.supplierId = val[0].supplierId
        formInfo.value.data.supplierName = val[0].supplierName
        formInfo.value.data.deviceType = val[0].deviceType
        formInfo.value.data.mark = val[0].trademark
        formInfo.value.data.deviceTypeValue = val[0].deviceTypeValue
        formInfo.value.data.deviceType = val[0].deviceType
        formInfo.value.data.unitId = val[0].unitId === -2 ? '' : val[0].unitId
        formInfo.value.data.financialClassifyType = val[0].financeType
        formInfo.value.data.financialClassifyTypeValue = val[0].financeTypeValue
        formInfo.value.data.primitiveOriginalAmount = val[0].price
        formInfo.value.data.acceptanceUser = val[0].acceptanceUser
        formInfo.value.data.acceptanceUserName = val[0].acceptanceUserName
        formInfo.value.data.acceptanceDate = val[0].acceptanceDate
        formInfo.value.data.purchUser = val[0].purchUser
        formInfo.value.data.purchUserName = val[0].purchUserName
        formInfo.value.data.purchDate = val[0].purchDate
        formInfo.value.data.deprMonthsLimit = val[0].deprMonthsLimit % 12
        formInfo.value.data.deprYearsLimit = Math.floor(
          val[0].deprMonthsLimit / 12
        )
        if (formInfo.value.data.financialClassifyTypeValue) {
          formInfo.value.data.isFinanceAsset = 1
          formInfo.value.data['assetType'] =
            val[0].preAssetType === -2 ? '' : val[0].preAssetType

          getDepreciation(formInfo.value.data.financialClassifyType)

          formInfo.value.data.netAmount = utils.Subtr(
            utils.Subtr(
              utils.Subtr(
                formInfo.value.data.originalAmount || 0,
                formInfo.value.data.residualAmount || 0
              ),
              formInfo.value.data.sumDeprAmount || 0
            ),
            formInfo.value.data.deprPreparation || 0
          )
          proxy.$nextTick(() => {
            formInfo.value.baseInfoRules.financialClassifyTypeValue = [
              {
                required: true,
                message: '请选择资产财务分类',
                trigger: 'change',
              },
            ]

            if (
              formInfo.value.data.isFinanceAsset &&
              !(formInfo.value.data.useStatus == 1)
            ) {
              // formInfo.value.baseInfoRules.assetUseDeptVOList = [
              //   {
              //     required: true,
              //   },
              // ]
            } else {
              // formInfo.value.baseInfoRules.assetUseDeptVOList = [
              //   {
              //     required: false,
              //   },
              // ]

              if (assetAmortizationDeptTableForm.value) {
                assetAmortizationDeptTableForm.value.clearValidate()
              }
            }
          })
        }

        proxy.$nextTick(() => {
          formInfo.value.data.increaseType = 0 //增加方式默认为直接购入
          formInfo.value.data.assetCapitalSourceVOList[0].amount =
            formInfo.value.data.primitiveOriginalAmount
        })
        formInfo.value.data.temporaryPurch = 0
        formInfo.value.data.originalAmount =
          formInfo.value.data.primitiveOriginalAmount
      }
    })
  },
  {
    immediate: true,
  }
)
watch(
  () => formInfo.value.data.temporaryPurch,
  (val) => {
    formInfo.value.baseInfoFieldList.find((item) => {
      if (item.value === 'supplierName') {
        if (val == 1) {
          item.required = false
          formInfo.value.baseInfoRules.supplierName = [
            {
              required: false,
              message: '请输入供应商',
              trigger: 'blur',
            },
          ]
        } else {
          item.required = true
          formInfo.value.baseInfoRules.supplierName = [
            {
              required: true,
              message: '请输入供应商',
              trigger: 'blur',
            },
          ]
        }
      }
    })
  }
)

watch(
  //初始原值
  () => formInfo.value.data.primitiveOriginalAmount,
  (value) => {
    if (!props.canModifyModule) {
      formInfo.value.data.originalAmount = value
    }
    formInfo.value.data.netAmount = utils.Subtr(
      utils.Subtr(
        utils.Subtr(
          formInfo.value.data.originalAmount || 0,
          formInfo.value.data.residualAmount || 0
        ),
        formInfo.value.data.sumDeprAmount || 0
      ),
      formInfo.value.data.deprPreparation || 0
    )
  }
)

watch(
  //原值
  () => formInfo.value.data.originalAmount,
  (value) => {
    if (flag.value) {
      let residualRate = formInfo.value.data.residualRate
        ? formInfo.value.data.residualRate
        : 0
      if (residualRate) {
        formInfo.value.data.residualAmount =
          utils.accMul(formInfo.value.data.residualRate, value) / 100
      }
      let residualAmount = formInfo.value.data.residualAmount
        ? formInfo.value.data.residualAmount
        : 0
      let sumDeprAmount = formInfo.value.data.sumDeprAmount
        ? formInfo.value.data.sumDeprAmount
        : 0
      let deprPreparation = formInfo.value.data.deprPreparation
        ? formInfo.value.data.deprPreparation
        : 0
      let netAmount = utils.Subtr(
        utils.Subtr(
          utils.Subtr(value || 0, residualAmount || 0),
          sumDeprAmount || 0
        ),
        deprPreparation || 0
      )
      formInfo.value.data.netAmount = netAmount
      changeMouthDepr()
    }
  }
)

watch(
  //折旧方法
  () => formInfo.value.data.deprMethodType,
  (value) => {
    if (flag.value) {
      changeMouthDepr()
    }
    if (value == '0') {
      //如果不折旧，那么隐藏所有跟折旧有关的值，并置为0
      showFinanceFieldListItem(false, 'deprMonthsLimit')
      // showFinanceFieldListItem(false, 'residualAmount')
      // showFinanceFieldListItem(false, 'residualRate')
      showFinanceFieldListItem(false, 'deprPreparation')
      showFinanceFieldListItem(false, 'sumDeprAmount')
      showFinanceFieldListItem(false, 'deprConvention')
      showFinanceFieldListItem(false, 'monthDeprRate')
      showFinanceFieldListItem(false, 'monthDeprAmount')

      formInfo.value.data.deprPreparation = 0
      formInfo.value.data.deprMonthsLimit = 0
      formInfo.value.data.deprYearsLimit = 0
      // formInfo.value.data.residualAmount = 0
      // formInfo.value.data.residualRate = 0
      formInfo.value.data.sumDeprAmount = 0
      formInfo.value.data.deprConvention = 0
    } else {
      showFinanceFieldListItem(true, 'deprMonthsLimit')
      // showFinanceFieldListItem(true, 'residualAmount')
      // showFinanceFieldListItem(true, 'residualRate')
      showFinanceFieldListItem(true, 'deprPreparation')
      showFinanceFieldListItem(true, 'sumDeprAmount')
      showFinanceFieldListItem(true, 'deprConvention')
      showFinanceFieldListItem(true, 'monthDeprRate')
      showFinanceFieldListItem(true, 'monthDeprAmount')
    }
  }
)
watch(
  //减值准备
  () => formInfo.value.data.deprPreparation,
  (value) => {
    if (flag.value) {
      let originalAmount = formInfo.value.data.originalAmount
        ? formInfo.value.data.originalAmount
        : 0
      let sumDeprAmount = formInfo.value.data.sumDeprAmount
        ? formInfo.value.data.sumDeprAmount
        : 0
      let residualAmount = formInfo.value.data.residualAmount
        ? formInfo.value.data.residualAmount
        : 0
      let netAmount = utils.Subtr(
        utils.Subtr(
          utils.Subtr(originalAmount || 0, residualAmount || 0),
          sumDeprAmount || 0
        ),
        value || 0
      )
      formInfo.value.data.netAmount = netAmount
      changeMouthDepr()
    }
  }
)
watch(
  //累计折旧
  () => formInfo.value.data.sumDeprAmount,
  () => {
    if (flag.value) {
      let originalAmount = formInfo.value.data.originalAmount
        ? formInfo.value.data.originalAmount
        : 0
      let sumDeprAmount = formInfo.value.data.sumDeprAmount
        ? formInfo.value.data.sumDeprAmount
        : 0
      let residualAmount = formInfo.value.data.residualAmount
        ? formInfo.value.data.residualAmount
        : 0
      let deprPreparation = formInfo.value.data.deprPreparation
        ? formInfo.value.data.deprPreparation
        : 0
      let netAmount = utils.Subtr(
        utils.Subtr(
          utils.Subtr(originalAmount || 0, residualAmount || 0),
          sumDeprAmount || 0
        ),
        deprPreparation || 0
      )
      formInfo.value.data.netAmount = netAmount
    }
  }
)

watch(
  //折旧月限
  () => formInfo.value.data.deprMonthsLimit,
  () => {
    if (flag.value) {
      changeMouthDepr()
    }
  }
)
watch(
  //折旧月限
  () => formInfo.value.data.deprYearsLimit,
  () => {
    if (flag.value) {
      changeMouthDepr()
    }
  }
)

watch(
  //是否财务资产
  () => formInfo.value.data.isFinanceAsset,
  (val) => {
    if (val) {
      if (flag.value) {
        if (!props.canModifyModule) {
          formInfo.value.data.originalAmount =
            formInfo.value.data.primitiveOriginalAmount
        }
        if (formInfo.value.data.financialClassifyType > 0) {
          getDepreciation(formInfo.value.data.financialClassifyType)
        }
        if (
          formInfo.value.data.assetUseDeptVOList.length &&
          !changeUseDeptNameFlag.value &&
          Number(formInfo.value.data.useStatus) === 2
        ) {
          // formInfo.value.data.assetUseDeptVOList[
          //   formInfo.value.data.assetUseDeptVOList.length - 1
          // ].useDeptName = formInfo.value.data.useDeptName
          // formInfo.value.data.assetUseDeptVOList[
          //   formInfo.value.data.assetUseDeptVOList.length - 1
          // ].useDeptId = formInfo.value.data.useDeptId
          // formInfo.value.data.assetUseDeptVOList[
          //   formInfo.value.data.assetUseDeptVOList.length - 1
          // ].rate = 100
        }
        formInfo.value.data.netAmount = utils.Subtr(
          utils.Subtr(
            utils.Subtr(
              formInfo.value.data.originalAmount || 0,
              formInfo.value.data.residualAmount || 0
            ),
            formInfo.value.data.sumDeprAmount || 0
          ),
          formInfo.value.data.deprPreparation || 0
        )
      }

      formInfo.value.baseInfoRules.financialClassifyTypeValue = [
        {
          required: true,
          message: '请选择资产财务分类',
          trigger: 'change',
        },
      ]
    } else {
      formInfo.value.baseInfoRules.financialClassifyTypeValue = [
        {
          required: false,
          message: '请选择资产财务分类',
          trigger: 'change',
        },
      ]
    }
    if (val && !(formInfo.value.data.useStatus == 1)) {
      // formInfo.value.baseInfoRules.assetUseDeptVOList = [
      //   {
      //     required: true,
      //   },
      // ]
    } else {
      // formInfo.value.baseInfoRules.assetUseDeptVOList = [
      //   {
      //     required: false,
      //   },
      // ]

      if (assetAmortizationDeptTableForm.value) {
        assetAmortizationDeptTableForm.value.clearValidate()
      }
    }
  }
)

watch(
  //是否计量资产
  () => formInfo.value.data.isMetering,
  (val) => {
    if (val) {
      let measurementNameRule = [
        {
          required: true,
          message: '请输入标准名称',
          trigger: 'blur',
        },
      ]
      formInfo.value.measurementInfoRules.measurementName = measurementNameRule
      formInfo.value.data.measurementName = formInfo.value.data.assetName
    } else {
      let measurementNameRule = [
        {
          required: false,
          message: '请输入标准名称',
          trigger: 'blur',
        },
      ]
      formInfo.value.measurementInfoRules.measurementName = measurementNameRule
    }
  }
)
watch(
  //维保商
  () => formInfo.value.data.maintenanceProviderName,
  (val) => {
    if (val) {
      maintenanceContactsDisabled.value = false
      selectMaintenanceContactsInfo.value.query.orgId =
        formInfo.value.data.maintenanceProvider
    } else {
      maintenanceContactsDisabled.value = true
      selectMaintenanceContactsInfo.value.query.orgId = ''
    }
  }
)
watch(
  //是否财务资产字段的取值判断为资产财务分类是否有值
  () => formInfo.value.data.financialClassifyTypeValue,
  (val) => {
    if (flag.value) {
      if (val) {
        formInfo.value.data.isFinanceAsset = 1
      } else {
        formInfo.value.data.isFinanceAsset = 0
      }
    }
  }
)
watch(
  //监听一个必有的字段，确保初始化之后flag为true
  () => formInfo.value.data.assetName,
  () => {
    proxy.$nextTick(() => {
      flag.value = true
    })
  }
)
watch(
  //计量资产的失效日期=检定周期+上次检定时间
  () => formInfo.value.data.verificationPeriod,
  (val) => {
    if (val != null && formInfo.value.data.verificationDate) {
      let date1 = new Date(formInfo.value.data.verificationDate)
      date1.setMonth(date1.getMonth() + formInfo.value.data.verificationPeriod)
      let month =
        date1.getMonth() + 1 > 9
          ? date1.getMonth() + 1
          : 0 + '' + (date1.getMonth() + 1)
      let date =
        date1.getDate() > 9 ? date1.getDate() : 0 + '' + date1.getDate()
      formInfo.value.data.validityDate =
        date1.getFullYear() + '-' + month + '-' + date
    }
  }
)
watch(
  () => formInfo.value.data.verificationDate,
  (val) => {
    if (val != null && formInfo.value.data.verificationPeriod) {
      let date1 = new Date(formInfo.value.data.verificationDate)
      date1.setMonth(date1.getMonth() + formInfo.value.data.verificationPeriod)
      let month =
        date1.getMonth() + 1 > 9
          ? date1.getMonth() + 1
          : 0 + '' + (date1.getMonth() + 1)
      let date =
        date1.getDate() > 9 ? date1.getDate() : 0 + '' + date1.getDate()
      formInfo.value.data.validityDate =
        date1.getFullYear() + '-' + month + '-' + date
    }
  }
)
watch(
  () => props.inventoryLocation, //盘点位置
  (val) => {
    console.log(props.inventoryLocation, flag.value, 'props.inventoryLocation')
    if (flag.value && props.inventoryLocation) {
      if (val === 1) {
        //盘点位置为部门，增加方式默认为盘盈，不可编辑；使用状态为正常使用，不可编辑。
        //使用人，存放地点，计量单位改为非必填
        setTimeout(() => {
          formInfo.value.data.useStatus = 2
        }, 0)
        // formInfo.value.rules.useUserName[0].required = false
        // showFieldListItem(true, 'useDeptName')
        showFieldListItem(false, 'depotName')
      } else if (val === 2) {
        //盘点位置为仓库，新增盘盈页字段显示。管理部门由仓库联动。标*为必填。
        //增加方式默认为盘盈，不可编辑。使用状态为待领用，不可编辑
        setTimeout(() => {
          formInfo.value.data.useStatus = 1
        }, 0)
        // formInfo.value.rules.increaseType[0].required = false
        // formInfo.value.rules.useStatus[0].required = false
        // showFieldListItem(false, 'useDeptName')
        showFieldListItem(true, 'depotName')
        // showFieldListItem(false, 'useUserName')
      }
    }
  },
  {
    immediate: true,
    // deep: true,
  }
)
onMounted(() => {
  setMedicalRepairWarnTime()
  initRules()
  getUnitList()
  // 如果是流程则进入页面需要请求会计期间
  if (proxy.$route.query.processInstanceId) {
    _getCurrentFiscalPeriod()
  } else {
    setDisabledDate()
  }
  if (props.id) {
    if (props.type === 'create') {
      //复制并新增type:'create'&&this.id同时存在
      getStatus()
    } else {
      formInfo.value.baseInfoFieldList.forEach((item) => {
        if (item.value === 'assetCode') {
          item.disabled = true
        }
      })
      // formInfo.value.baseInfoFieldList[1].disabled = true
    }
    if (props.canModifyModule === 'noFinanceAsset') {
      //信息补录
      formInfo.value.baseInfoFieldList.forEach((item) => {
        if (
          item.required ||
          item.value == 'isFinanceAsset' ||
          item.value === 'temporaryPurch'
        ) {
          item.disabled = true
        }
      })

      formInfo.value.commonInfoFieldList.forEach((item) => {
        if (item.required) {
          item.disabled = true
        }
      })
      formInfo.value.financeInfoFieldList.forEach((item) => {
        item.disabled = true
      })
      assetAmortizationDeptTableInfo.value.handle.btList.forEach((item) => {
        item.show = false
      })
      assetCapitalSourceTableInfo.value.handle.btList.forEach((item) => {
        item.show = false
      })
      formInfo.value.baseInfoFieldList.forEach((item, index) => {
        if (item.value === 'useStatus') {
          formInfo.value.baseInfoFieldList[index] = {
            label: '使用状态',
            value: 'useStatus',
            type: 'select-model',
            code: 'asset_use_status',
            required: true,
            disabled: true,
            event: 'useStatus',
          }
        }
      })
    }
    if (props.type === 'editSurplus') {
      //新增盘盈
      formInfo.value.baseInfoFieldList.forEach((item) => {
        if (item.value === 'increaseType' || item.value === 'useStatus') {
          item.disabled = true
        }
      })
    }
    getDetails()
    flag.value = false
  } else {
    isShowAddEquipment.value = true
    if (
      (props.buildCardData && props.buildCardData.length) ||
      props.type === 'createSurplus' ||
      props.type === 'editSurplus'
    ) {
      isShowAddEquipment.value = false
    }
    if (props.type === 'createSurplus') {
      //新增盘盈
      formInfo.value.data.increaseType = 3
      formInfo.value.baseInfoFieldList.forEach((item) => {
        if (item.value === 'increaseType' || item.value === 'useStatus') {
          item.disabled = true
        }
      })
      formInfo.value.data = {
        ...formInfo.value.data,
        ...props.fillData,
      }
      console.log(formInfo.value.baseInfoFieldList)
    }
    getStatus()
  }
})
function setMedicalRepairWarnTime() {
  let value = formInfo.value.data.isMedicalEquipment
  const systemConfig = proxy.$store.state.permission.systemConfig
  if (value == 1) {
    formInfo.value.data.repairWarnTime = systemConfig.medical_repair_warn_time
  } else if (value == 0) {
    formInfo.value.data.repairWarnTime =
      systemConfig.not_medical_repair_warn_time
  }
}
function changeValidate(value, str, ref) {
  proxy.$nextTick(() => {
    proxy.$refs[ref].clearValidate(str)
  })
}
function _getCurrentFiscalPeriod() {
  getCurrentFiscalPeriod(2).then((resp) => {
    if (resp && resp.success && resp.data) {
      currentAccountingIntervalIsFlow.value = resp.data.startDate
      setDisabledDate(currentAccountingIntervalIsFlow.value)
    } else {
      proxy.$message({
        type: 'error',
        duration: 3500,
        message: '未开启会计期间，请先开启会计期间!',
        showClose: true,
      })
    }
  })
}
function setDisabledDate(flowDate) {
  productionTimePickerOptions.value = {
    disabledDate(time) {
      if (flowDate || props.currentAccountingInterval) {
        return (
          time.getTime() <
          new Date(flowDate || props.currentAccountingInterval).getTime() -
            24 * 60 * 60 * 1000
        )
      }
    },
  }
}
function openAssetCapitalProjectList(index) {
  if (!props.canModifyModule || props.canModifyModule === 'noFinanceAsset') {
    //打开资金项目弹窗
    selectAssetCapitalProjectInfo.value.index = index
    let assetCapitalSourceVOListElement =
      formInfo.value.data.assetCapitalSourceVOList[index]
    if (
      assetCapitalSourceVOListElement.capitalProjectList &&
      assetCapitalSourceVOListElement.capitalProjectList.length
    ) {
      selectAssetCapitalProjectInfo.value.checkedRowList =
        assetCapitalSourceVOListElement.capitalProjectList
    } else {
      selectAssetCapitalProjectInfo.value.checkedRowList = []
    }
    // selectAssetCapitalProjectInfo.value.query['assetCapitalSourceDictId'] = {
    //   queryType: 'EQUALS',
    //   value: assetCapitalSourceVOListElement.code,
    // }
    if (props.id) {
      selectAssetCapitalProjectInfo.value.queryParams.assetId = props.id
    }
    selectAssetCapitalProjectInfo.value.visible = true
  }
}
function selectAssetCapitalProjectCallBack(data, arr) {
  //资金项目
  if (data && data.length) {
    let capitalProjectName = data.map((item) => item.name).toString()
    // let amount = 0
    // data.map((item) => {
    //   amount += item.useAmount
    // })

    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectName = capitalProjectName
    // formInfo.value.data.assetCapitalSourceVOList[
    //   selectAssetCapitalProjectInfo.value.index
    // ].amount = amount

    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectList = data.map((item) => {
      return {
        assetCapitalProjectId: item.id,
        useAmount: item.useAmount,
      }
    })

    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectList.forEach((item) => {
      arr.forEach((el) => {
        if (el.id === item.id) {
          item.useAmount = el.useAmount
        }
      })
    })
  } else {
    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectName = ''

    formInfo.value.data.assetCapitalSourceVOList[
      selectAssetCapitalProjectInfo.value.index
    ].capitalProjectList = []
  }
}
function changeCapitalSource(val, index) {
  formInfo.value.data.assetCapitalSourceVOList[index].capitalProjectList = []
}

function changeAmount() {
  console.log(
    !(
      props.buildCardData &&
      props.buildCardData.length &&
      formInfo.value.data.orderSourceId &&
      formInfo.value.data.orderSourceId !== -2 &&
      props.type !== 'create'
    )
  )
  if (
    !(props.buildCardData && props.buildCardData.length) &&
    !(
      formInfo.value.data.orderSourceId &&
      formInfo.value.data.orderSourceId !== -2 &&
      props.type !== 'create'
    )
  ) {
    changeAmountFlag.value = true
    let primitiveOriginalAmount = 0
    if (
      formInfo.value.data.assetCapitalSourceVOList &&
      formInfo.value.data.assetCapitalSourceVOList.length
    ) {
      formInfo.value.data.assetCapitalSourceVOList.forEach((item) => {
        primitiveOriginalAmount = proxy.$fn.accAdd(
          item.amount || 0,
          primitiveOriginalAmount
        )
      })
    }
    formInfo.value.data.primitiveOriginalAmount = primitiveOriginalAmount
  }
}
function handleEventBaseForm(event) {
  if (event === 'useStatus') {
    formInfo.value.data.depotId = -2
    formInfo.value.data.depotName = ''
    // formInfo.value.data.useDeptId = -2
    // formInfo.value.data.useDeptName = ''
  } else if (event === 'primitiveOriginalAmount') {
    if (
      !changeAmountFlag.value &&
      formInfo.value.data.assetCapitalSourceVOList &&
      formInfo.value.data.assetCapitalSourceVOList.length === 1
    ) {
      formInfo.value.data.assetCapitalSourceVOList[
        formInfo.value.data.assetCapitalSourceVOList.length - 1
      ].amount = formInfo.value.data.primitiveOriginalAmount
    }
  } else if (event === 'temporaryPurch') {
    formInfo.value.data.supplierName = ''
    formInfo.value.data.supplierId = -2
  } else if (event === 'primitiveOriginalAmountSetValue') {
    formInfo.value.data.primitiveOriginalAmount =
      formInfo.value.data.price +
      formInfo.value.data.installCost +
      formInfo.value.data.transportCost +
      formInfo.value.data.taxCost
  }
}
function openDepotWindow() {
  selectDepotInfo.value.visible = true
}
function selectDepotCallBack(row) {
  if (row && row.id) {
    formInfo.value.data.depotId = row.id
    formInfo.value.data.depotName = row.name
  } else {
    formInfo.value.data.depotId = -2
    formInfo.value.data.depotName = ''
  }
}
function handleResponse(response, file) {
  return file
}
function openAmortizationDept(index) {
  if (!props.canModifyModule) {
    //新增使用部门
    let ids = []
    if (
      formInfo.value.data.assetUseDeptVOList &&
      formInfo.value.data.assetUseDeptVOList.length
    ) {
      formInfo.value.data.assetUseDeptVOList.forEach((item) => {
        if (item.useDeptName) {
          ids.push(item.useDeptId)
        }
      })
    }
    addAssetAmortizationDeptInfo.value.query.idNotIn = String(ids)
    addAssetAmortizationDeptIndex.value = index
    addAssetAmortizationDeptInfo.value.visible = true
  }
}
function addDept() {
  formInfo.value.data.assetUseDeptVOList.push({
    useDeptName: '',
  })
  proxy.$nextTick(() => {
    assetAmortizationDeptTableForm.value.clearValidate()
  })
}
function selectAssetAmortizationDeptCallback(data) {
  changeUseDeptNameFlag.value = true
  if (data) {
    formInfo.value.data.assetUseDeptVOList.forEach((item, index) => {
      if (index === addAssetAmortizationDeptIndex.value) {
        item.useDeptName = data.name
        item.useDeptId = data.id
      }
    })
  } else {
    formInfo.value.data.assetUseDeptVOList.forEach((item, index) => {
      if (index === addAssetAmortizationDeptIndex.value) {
        item.useDeptName = ''
        item.useDeptId = -2
      }
    })
  }
  addAssetAmortizationDeptInfo.value.visible = false
}
function removeDept(row) {
  //删除使用部门
  formInfo.value.data.assetUseDeptVOList =
    formInfo.value.data.assetUseDeptVOList.filter((item) => item !== row)
}
function clearDept() {
  //清空使用部门
  formInfo.value.data.assetUseDeptVOList = [{ useDeptName: '' }]
}
function ifRenderRemoveDept() {
  if (formInfo.value.data.assetUseDeptVOList.length - 1) {
    return true
  } else {
    return false
  }
}
function ifRenderClearDept() {
  if (formInfo.value.data.assetUseDeptVOList.length === 1) {
    return true
  } else {
    return false
  }
}
function ifRenderRemoveSource() {
  if (formInfo.value.data.assetCapitalSourceVOList.length - 1) {
    return true
  } else {
    return false
  }
}
function addSource() {
  //增加资金来源
  formInfo.value.data.assetCapitalSourceVOList.push({
    code: '',
    amount: 0,
  })
}
function removeSource(row) {
  //删除资金来源
  formInfo.value.data.assetCapitalSourceVOList =
    formInfo.value.data.assetCapitalSourceVOList.filter((item) => item !== row)
  if (!(props.buildCardData && props.buildCardData.length)) {
    changeAmount()
  }
}
function getDepreciation(id) {
  if (id && id !== -2) {
    getCategoryDetailsById(id).then((res) => {
      if (res && res.success) {
        let row = res.data
        formInfo.value.data.deprConvention = row.deprConvention

        formInfo.value.data.deprConventionValue = row.deprConventionValue

        formInfo.value.data.deprMethodType = row.deprMethodType

        formInfo.value.data.deprMethodTypeValue = row.deprMethodTypeValue

        // formInfo.value.data.deprMonthsLimit = row.deprMonthsLimit
        // formInfo.value.data.residualRate = row.residualRate
        // let residualAmount =
        //   utils.accMul(
        //     formInfo.value.data.residualRate,
        //     formInfo.value.data.originalAmount || 0
        //   ) / 100
        // formInfo.value.data.residualAmount = residualAmount
      }
    })
  }
}
function addEquipment() {
  equipmentInfo.value.visible = true
}
function changeEquipment(data) {
  equipmentInfo.value.visible = false
  if (data) {
    if (data.unitId !== -2) {
      formInfo.value.data.unitId = data.unitId
    } else {
      formInfo.value.data.unitId = ''
    }
    formInfo.value.data.deviceTypeCategory = data.deviceTypeCategory
    formInfo.value.data.brandName = data.brandName
    formInfo.value.data.standard = data.standard
    formInfo.value.data.deviceTypeValue = data.deviceTypeValue
    formInfo.value.data.deviceType = data.deviceType
    formInfo.value.data.mark = data.trademark
    formInfo.value.data.productId = data.id
    formInfo.value.data.assetName = data.commonName
    // 供应商 管理部门 设备标识 是否维保 是否为计量资产 折旧月限 折旧惯例
    formInfo.value.data.supplierId = data.supplierId
    formInfo.value.data.supplierName = data.supplierName
    formInfo.value.data.manageDeptName = data.deptName
    formInfo.value.data.manageDeptId = data.deptId
    formInfo.value.data.assetMark = data.assetMark
    formInfo.value.data.isMaintenance = data.isMaintenance
    formInfo.value.data.isMaintenanceName = data.isMaintenanceName
    formInfo.value.data.isMetering = data.isMetering
    formInfo.value.data.isMeteringName = data.isMeteringName
    formInfo.value.data.deprMonthsLimit = data.deprMonthsLimit % 12
    formInfo.value.data.deprYearsLimit = Math.floor(data.deprMonthsLimit / 12)
    formInfo.value.data.deprConvention = data.deprConvention
    formInfo.value.data.deprConventionValue = data.deprConventionValue
    formInfo.value.data.repairWarnTime = data.repairWarnTime
    formInfo.value.data.deprMethodType = data.deprMethodType
    formInfo.value.data.deprMethodTypeValue = data.deprMethodTypeValue
    formInfo.value.data.isMedicalEquipment = data.isMedicalEquipment
    formInfo.value.data.isMedicalEquipmentValue = data.isMedicalEquipmentValue
    formInfo.value.data.repairWarnTime = data.repairWarnTime

    if (data.financeTypeValue) {
      formInfo.value.data.isFinanceAsset = 1

      formInfo.value.data.financialClassifyTypeValue = data.financeTypeValue

      formInfo.value.data.financialClassifyType = data.financeType
      formInfo.value.data.classifyTypeValue = data.assetTypeValue
      formInfo.value.data.classifyType = data.assetType
    } else {
      formInfo.value.data.isFinanceAsset = 0
      formInfo.value.data.financialClassifyType = data.financeType

      formInfo.value.data.financialClassifyTypeValue = data.financeTypeValue

      formInfo.value.data.classifyTypeValue = data.assetTypeValue
      formInfo.value.data.classifyType = data.assetType
    }
  }
}

// 初始化校验规则
function initRules() {
  formInfo.value.baseInfoRules = proxy.$initRules(
    formInfo.value.baseInfoFieldList
  )
  formInfo.value.commonRules = proxy.$initRules(
    formInfo.value.commonInfoFieldList
  )
  formInfo.value.maintenanceInfoRules = proxy.$initRules(
    formInfo.value.maintenanceInfoFieldList
  )
  formInfo.value.maintenanceInfoRules.maintenancePhone = [
    { validator: proxy.$validate.cellphone, trigger: 'blur' },
  ]
  if (props.canModifyModule === 'noFinanceAsset') {
    formInfo.value.baseInfoRules.assetCapitalSourceVOList = [
      { required: false },
    ]
  }
}
//获取计量单位列表
function getUnitList() {
  getUnitAll().then((resp) => {
    if (resp && resp.success && resp.data && resp.data.length > 0) {
      listTypeInfo.value.unitList = resp.data.map(function (item) {
        return { key: item.name, value: item.id }
      })
    }
  })
}
function handleEvent(e) {
  // if (e === 'residualAmount') {
  //   let residualRate =
  //     utils.accDiv(
  //       formInfo.value.data.residualAmount,
  //       formInfo.value.data.originalAmount
  //     ) * 100
  //   formInfo.value.data.residualRate = residualRate
  // } else if (e === 'residualRate') {
  //   let residualAmount =
  //     utils.accMul(
  //       formInfo.value.data.residualRate,
  //       formInfo.value.data.originalAmount
  //     ) / 100
  //   formInfo.value.data.residualAmount = residualAmount
  // }
}

function changeMouthDepr() {
  let value = formInfo.value.data.deprMethodType

  let deprMonthsLimit =
    (formInfo.value.data.deprYearsLimit || 0) * 12 +
    (formInfo.value.data.deprMonthsLimit || 0)
  let originalAmount = formInfo.value.data.originalAmount
    ? formInfo.value.data.originalAmount
    : 0
  let deprPreparation = formInfo.value.data.deprPreparation
    ? formInfo.value.data.deprPreparation
    : 0

  if (value == '0') {
    //不折旧
    formInfo.value.data.monthDeprRate = 0
    formInfo.value.data.monthDeprAmount = 0
  } else if (value == '1') {
    //平均折旧法
    let residualRate = 0
    if (deprMonthsLimit) {
      let monthDeprRate = utils.accDiv(
        utils.Subtr(1, residualRate),
        deprMonthsLimit
      )
      let monthDeprAmount

      monthDeprAmount = utils.accMul(
        utils.Subtr(originalAmount || 0, deprPreparation || 0),
        utils.getAssetRate(monthDeprRate)
      )

      formInfo.value.data.monthDeprRate = monthDeprRate * 100
      formInfo.value.data.monthDeprAmount = monthDeprAmount
    } else {
      formInfo.value.data.monthDeprRate = 0
      formInfo.value.data.monthDeprAmount = 0
    }
  }
}
function openAssetClassifyWindow() {
  if (!props.canModifyModule) {
    selectAssetClassifyInfo.value.visible = true
  }
}
function openUseDeptWindow() {
  selectUseDeptInfo.value.visible = true
}
function openManageDeptWindow() {
  // if (!props.canModifyModule) {
    selectCommonDeptInfo.value.visible = true
  // }
}
// function openFinanceDeptWindow() {
//   if (!props.canModifyModule) {
//     selectFinanceDeptInfo.value.visible = true
//   }
// }
function openSupplierWindow() {
  selectProductSupplier.value.visible = true
}
function openMaintenanceProviderWindow() {
  selectMaintenanceProvider.value.visible = true
}

function openKeeperUserList() {
  selectKeeperUserInfo.value.visible = true
}
function openAcceptanceUserList() {
  selectAcceptanceUserInfo.value.visible = true
}
function openPurchUserList() {
  selectPurchUserInfo.value.visible = true
}
function openApplicationUserList() {
  selectApplicationUserInfo.value.visible = true
}
function openReceiveUserList() {
  selectReceiveUserInfo.value.visible = true
}
function openMaintenanceContactsList() {
  if (!maintenanceContactsDisabled.value) {
    if (
      !formInfo.value.data.classifyTypeValue
      // || !(formInfo.value.data.useDeptName || formInfo.value.data.depotName)
    ) {
      proxy.$message.warning('请先选择资产分类、使用部门或者仓库')
      return
    }
    selectMaintenanceContactsInfo.value.query.orgId =
      formInfo.value.data.maintenanceProvider === -2
        ? ''
        : formInfo.value.data.maintenanceProvider
    selectMaintenanceContactsInfo.value.query.assetId =
      formInfo.value.data.assetId === -2 ? '' : formInfo.value.data.assetId
    selectMaintenanceContactsInfo.value.query.deptId =
      formInfo.value.data.useDeptId === -2 ? '' : formInfo.value.data.useDeptId
    selectMaintenanceContactsInfo.value.query.depotId =
      formInfo.value.data.depotId === -2 ? '' : formInfo.value.data.depotId
    selectMaintenanceContactsInfo.value.query.assetClassifyId =
      formInfo.value.data.classifyType === -2
        ? ''
        : formInfo.value.data.classifyType

    selectMaintenanceContactsInfo.value.visible = true
  }
}
function openHospitalMaintainerUserList() {
  if (
    !formInfo.value.data.classifyTypeValue
    // || !(formInfo.value.data.useDeptName || formInfo.value.data.depotName)
  ) {
    proxy.$message.warning('请先选择资产分类、使用部门或者仓库')
    return
  }
  selectHospitalMaintainerInfo.value.query.assetId =
    formInfo.value.data.assetId === -2 ? '' : formInfo.value.data.assetId
  selectHospitalMaintainerInfo.value.query.deptId =
    formInfo.value.data.useDeptId === -2 ? '' : formInfo.value.data.useDeptId
  selectHospitalMaintainerInfo.value.query.depotId =
    formInfo.value.data.depotId === -2 ? '' : formInfo.value.data.depotId
  selectHospitalMaintainerInfo.value.query.assetClassifyId =
    formInfo.value.data.classifyType === -2
      ? ''
      : formInfo.value.data.classifyType
  selectHospitalMaintainerInfo.value.visible = true
}
function openUseUserList() {
  // if (!props.canModifyModule) {
  selectUseUserInfo.value.visible = true
  // }
}
function openResponsibleUserList() {
  selectResponsibleUserInfo.value.visible = true
}
function openFinanceTypeWindow() {
  if (!props.canModifyModule) {
    selectSettingCategoryInfo.value.visible = true
  }
  console.log(formInfo.value.data)
}
function openDeviceTypeWindow() {
  selectSettingClassificationInfo.value.visible = true
}

function selectUseDeptCallback(row) {
  if (row) {
    // formInfo.value.data.useDeptId = row.id
    // formInfo.value.data.useDeptName = row.name
  } else {
    // formInfo.value.data.useDeptId = '.'
    // formInfo.value.data.useDeptName = ''
  }

  if (
    formInfo.value.data.assetUseDeptVOList.length &&
    !changeUseDeptNameFlag.value
  ) {
    // formInfo.value.data.assetUseDeptVOList[
    //   formInfo.value.data.assetUseDeptVOList.length - 1
    // ].useDeptName = formInfo.value.data.useDeptName
    // formInfo.value.data.assetUseDeptVOList[
    //   formInfo.value.data.assetUseDeptVOList.length - 1
    // ].useDeptId = formInfo.value.data.useDeptId
    // formInfo.value.data.assetUseDeptVOList[
    //   formInfo.value.data.assetUseDeptVOList.length - 1
    // ].rate = 100
  }
}
function selectCommonDeptCallback(row) {
  if (row) {
    formInfo.value.data.manageDeptId = row.id
    formInfo.value.data.manageDeptName = row.name
    // 如果使用部门没得数据 则带入到使用部门
    let isComplete = formInfo.value.data.assetUseDeptVOList.filter(
      (item) => item.useDeptName
    )
    if (!isComplete.length) {
      formInfo.value.data.assetUseDeptVOList[0].useDeptId = row.id
      formInfo.value.data.assetUseDeptVOList[0].useDeptName = row.name
      formInfo.value.data.assetUseDeptVOList[0].rate = 100
    }
  } else {
    formInfo.value.data.manageDeptId = ''
    formInfo.value.data.manageDeptName = ''
  }
}
// function selectFinanceDeptCallback(row) {
//   if (row) {
//     formInfo.value.data.financeDeptId = row.id
//     formInfo.value.data.financeDeptName = row.name
//   } else {
//     formInfo.value.data.financeDeptId = ''
//     formInfo.value.data.financeDeptName = ''
//   }
// }
function selectSupplierCallback(row) {
  if (row) {
    formInfo.value.data.supplierId = row.supplierId
    formInfo.value.data.supplierName = row.supplierName
  } else {
    formInfo.value.data.supplierId = ''
    formInfo.value.data.supplierName = ''
  }
}
function selectMaintenanceProviderCallback(row) {
  if (row) {
    formInfo.value.data.maintenanceProvider = row.maintenanceId

    formInfo.value.data.maintenanceProviderName = row.maintenanceName

    formInfo.value.data.maintenanceContacts = ''
    formInfo.value.data.maintenanceContactsName = ''
  } else {
    formInfo.value.data.maintenanceProvider = ''
    formInfo.value.data.maintenanceProviderName = ''
  }
}

function selectKeeperUserCallBack(row) {
  if (row) {
    formInfo.value.data.keeperUser = row.id
    formInfo.value.data.keeperUserName = row.name
  } else {
    formInfo.value.data.keeperUser = ''
    formInfo.value.data.keeperUserName = ''
  }
}
function selectAcceptanceUserCallBack(row) {
  if (row) {
    formInfo.value.data.acceptanceUser = row.id
    formInfo.value.data.acceptanceUserName = row.name
  } else {
    formInfo.value.data.acceptanceUser = ''
    formInfo.value.data.acceptanceUserName = ''
  }
}
function selectPurchUserCallBack(row) {
  if (row) {
    formInfo.value.data.purchUser = row.id
    formInfo.value.data.purchUserName = row.name
  } else {
    formInfo.value.data.purchUser = ''
    formInfo.value.data.purchUserName = ''
  }
}
function selectApplicationUserCallBack(row) {
  if (row) {
    formInfo.value.data.applicationUser = row.id
    formInfo.value.data.applicationUserName = row.name
  } else {
    formInfo.value.data.applicationUser = ''
    formInfo.value.data.applicationUserName = ''
  }
}
function selectReceiveUserCallBack(row) {
  if (row) {
    formInfo.value.data.receiveUser = row.id
    formInfo.value.data.receiveUserName = row.name
  } else {
    formInfo.value.data.receiveUser = ''
    formInfo.value.data.receiveUserName = ''
  }
}
function selectMaintenanceContactsCallBack(row) {
  if (row) {
    formInfo.value.data.maintenanceContacts = row.userId
    formInfo.value.data.maintenanceContactsName = row.name
    formInfo.value.data.maintenancePhone = row.tel
  } else {
    formInfo.value.data.maintenanceContacts = ''
    formInfo.value.data.maintenanceContactsName = ''
    formInfo.value.data.maintenancePhone = ''
  }
}
function selectHospitalMaintainerCallBack(row) {
  if (row) {
    formInfo.value.data.hospitalMaintainerUser = row.userId
    formInfo.value.data.hospitalMaintainerUserName = row.name
    formInfo.value.data.hospitalMaintainerPhone = row.tel
  } else {
    formInfo.value.data.hospitalMaintainerUser = ''
    formInfo.value.data.hospitalMaintainerUserName = ''
    formInfo.value.data.hospitalMaintainerPhone = ''
  }
}
function selectUseUserCallBack(row) {
  if (row) {
    formInfo.value.data.useUser = row.id
    formInfo.value.data.useUserName = row.name
  } else {
    formInfo.value.data.useUser = ''
    formInfo.value.data.useUserName = ''
  }
}
function selectResponsibleUserCallBack(row) {
  if (row) {
    formInfo.value.data.responsibleUser = row.id
    formInfo.value.data.responsibleUserName = row.name
  } else {
    formInfo.value.data.responsibleUser = ''
    formInfo.value.data.responsibleUserName = ''
  }
}
function selectSettingCategoryInfoCallBack(row) {
  if (row && row.id) {
    formInfo.value.data.financialClassifyType = row.id
    formInfo.value.data.financialClassifyTypeValue = row.name
    formInfo.value.data.deprConvention = row.deprConvention

    formInfo.value.data.deprConventionValue = row.deprConventionValue

    formInfo.value.data.deprMethodType = row.deprMethodType

    formInfo.value.data.deprMethodTypeValue = row.deprMethodTypeValue
    // formInfo.value.data.residualRate = row.residualRate
    // let residualAmount =
    //   utils.accMul(
    //     formInfo.value.data.residualRate,
    //     formInfo.value.data.originalAmount || 0
    //   ) / 100
    // formInfo.value.data.residualAmount = residualAmount
  } else {
    formInfo.value.data.financialClassifyType = ''
    formInfo.value.data.financialClassifyTypeValue = ''

    formInfo.value.data.deprConvention = ''
    formInfo.value.data.deprConventionValue = ''
    formInfo.value.data.deprMethodType = ''
    formInfo.value.data.deprMethodTypeValue = ''
    // formInfo.value.data.residualRate = ''
    // formInfo.value.data.residualAmount = ''
  }
}
function selectAssetClassifyInfoCallBack(row) {
  if (row && row.id) {
    formInfo.value.data.classifyType = row.id
    formInfo.value.data.classifyTypeValue = row.name

    formInfo.value.data.financialClassifyType = row.assetFinancialClassifyId

    formInfo.value.data.financialClassifyTypeValue =
      row.assetFinancialClassifyName

    formInfo.value.data.assetType = row.assetType
    formInfo.value.data.assetTypeValue = row.assetTypeValue
    formInfo.value.data.deprMonthsLimit = row.deprMonthsLimit % 12
    formInfo.value.data.deprYearsLimit = Math.floor(row.deprMonthsLimit / 12)
    // 顺便回显 管理部门 和 使用部门
    if (!formInfo.value.data.manageDeptId) {
      formInfo.value.data.manageDeptId = row.manageDeptId
      formInfo.value.data.manageDeptName = row.manageDeptName
    }
    let isComplete = formInfo.value.data.assetUseDeptVOList.filter(
      (item) => item.useDeptName
    )
    if (!isComplete.length) {
      formInfo.value.data.assetUseDeptVOList[0].useDeptId = row.manageDeptId
      formInfo.value.data.assetUseDeptVOList[0].useDeptName = row.manageDeptName
      formInfo.value.data.assetUseDeptVOList[0].rate = 100
    }

    getDepreciation(row.assetFinancialClassifyId)
  } else {
    formInfo.value.data.classifyType = '-2'
    formInfo.value.data.classifyTypeValue = ''
    formInfo.value.data.financialClassifyType = '-2'
    formInfo.value.data.financialClassifyTypeValue = ''
    formInfo.value.data.deprConvention = ''
    formInfo.value.data.deprConventionValue = ''
    formInfo.value.data.deprMethodType = ''
    formInfo.value.data.deprMethodTypeValue = ''
    formInfo.value.data.deprMonthsLimit = 0
    // formInfo.value.data.residualRate = ''
    formInfo.value.data.assetType = ''
    formInfo.value.data.assetTypeValue = ''
    formInfo.value.data.deprYearsLimit = 0
  }
}
function selectSettingClassificationInfoCallBack(row) {
  if (row) {
    formInfo.value.data.deviceType = row.id
    formInfo.value.data.deviceTypeValue = row.name
  } else {
    formInfo.value.data.deviceType = ''
    formInfo.value.data.deviceTypeValue = ''
  }
}
// 外部流程组件也需调用
function saveAndSubmit(flowData) {
  save(true, flowData)
}
function handleBatchShow() {
  dialogBatchSaveInfo.visible = true
}
function handleBatchSave() {
  save(false, {}, true)
  dialogBatchSaveInfo.visible = false
}
function handleBatchSaveAndSubmit() {
  save(true, {}, true)
  dialogBatchSaveInfo.visible = false
}
function handleClose() {
  dialogBatchSaveInfo.visible = false
  formBatchSaveInfo.data = {
    countNum: '',
  }
}

function save(isSaveAndSubmit, obj = {},isBatch) {
  formRefs.value = [formInfo.value.baseRef, formInfo.value.commonRef]
  let formRef = []
  if (
    props.canModifyModule !== 'noFinanceAsset' &&
    assetCapitalSourceTableForm.value
  ) {
    formRef.push(assetCapitalSourceTableForm.value)
  }
  if (formInfo.value.financeRef && formInfo.value.data.isFinanceAsset) {
    formRef.push(formInfo.value.financeRef)
  }
  if (formInfo.value.maintenanceRef && formInfo.value.data.isMaintenance) {
    formRef.push(formInfo.value.maintenanceRef)
  }
  if (formInfo.value.data.isMetering == 1) {
    formRef.push(formInfo.value.measurementRef)
  }

  if (
    formInfo.value.data.isFinanceAsset &&
    assetAmortizationDeptTableForm.value &&
    !(formInfo.value.data.useStatus == 1)
  ) {
    //使用部门的校验
    //资产卡片使用状态为【带领用】，计提标志为【不计提】折旧时，使用部门可不填
    formRef.push(assetAmortizationDeptTableForm.value)
  }
  formRefs.value = formRefs.value.concat(formRef)

  if (formInfo.value.data.assetCapitalSourceVOList.length) {
    //资金来源：一份资产卡片只能拥有一行相同的项目类型
    let warning = false
    formInfo.value.data.assetCapitalSourceVOList.some((e, index, arr) => {
      if (arr.filter((e1) => Number(e1.code) == Number(e.code)).length > 1) {
        warning = true
      }
    })
    if (warning) {
      proxy.$message.warning('一份资产卡片只能拥有一行相同的项目类型')
      return
    }
    let primitiveOriginalAmount = 0
    formInfo.value.data.assetCapitalSourceVOList.forEach((item) => {
      primitiveOriginalAmount = proxy.$fn.accAdd(
        item.amount || 0,
        primitiveOriginalAmount
      )
    })
    // 信息补录 已登记 不校验 金额相等
    if (
      primitiveOriginalAmount !== formInfo.value.data.primitiveOriginalAmount &&
      !(
        props.type === 'update' &&
        props.canModifyModule === 'noFinanceAsset' &&
        formInfo.value.data.status === 3
      )
      //  && (props.canModifyModule !== 'noFinanceAsset' || !props.canModifyModule)
    ) {
      proxy.$message.warning('资金来源金额合计要与金额相等！')
      return
    }
    let _warning = false
    let _warningIndex = []
    formInfo.value.data.assetCapitalSourceVOList.forEach((item, index) => {
      let useAmount = 0
      if (item.capitalProjectList && item.capitalProjectList.length) {
        item.capitalProjectList.forEach((el) => {
          useAmount = proxy.$fn.accAdd(el.useAmount || 0, useAmount)
        })
        if (useAmount > item.amount) {
          _warning = true
          _warningIndex.push(index + 1)
        }
      }
    })
    if (_warning) {
      proxy.$message.warning(
        `【第${String(
          _warningIndex
        )}行】的资金项目使用金额之和不能大于资金来源金额！`
      )
      return
    }
  }
  if (
    formInfo.value.data.assetUseDeptVOList.length > 0 &&
    formInfo.value.data.isFinanceAsset
  ) {
    //使用部门
    let rate = 0
    let assetUseDeptVOList = formInfo.value.data.assetUseDeptVOList.filter(
      (item) => {
        rate = proxy.$fn.accAdd(rate, item.rate || 0)
        return !!item.useDeptName
      }
    )

    if (rate !== 100 && assetUseDeptVOList.length) {
      proxy.$message.warning('使用部门的占比总值必须为100%!')
      return
    }
  }

  if (
    !props.currentAccountingInterval &&
    !currentAccountingIntervalIsFlow.value &&
    formInfo.value.data.isFinanceAsset
  ) {
    proxy.$message({
      type: 'error',
      duration: 3500,
      message: '未开启会计期间，请先开启会计期间!',
      showClose: true,
    })
  } else {
    proxy.$fn
      .checkForm(formRefs.value)
      .then(() => {
        let deprMonthsLimit =
          (formInfo.value.data.deprYearsLimit || 0) * 12 +
          (formInfo.value.data.deprMonthsLimit || 0)
        //折旧月限和已使用月数相同，净值必须为0，否则不允许折旧月限和已使用月数相同。
        if (formInfo.value.data.isFinanceAsset) {
          if (
            deprMonthsLimit === formInfo.value.data.monthsUsed &&
            formInfo.value.data.netAmount !== 0 &&
            formInfo.value.data.deprMethodType != '0'
          ) {
            proxy.$message({
              type: 'warning',
              duration: 3500,
              message: '折旧月限和已使用月数相同，净值必须为0',
              showClose: true,
            })
            return
          }
        }
        let api
        formInfo.value.data.billFilePath = formInfo.value.data.fileUrlList
          ? formInfo.value.data.fileUrlList.join(',')
          : ''
        const params = {
          ...proxy.$fn.deepClone(formInfo.value.data),
        }
        params.deprMonthsLimit = deprMonthsLimit
        // 复制并新增 isBeginCard
        if (props.type === 'create' && props.id) {
          params.isBeginCard = 0
          params.isBeginCardValue = '否'
        }
        if (
          !(
            params.assetCapitalSourceVOList &&
            params.assetCapitalSourceVOList[0].code
          )
        ) {
          delete params.assetCapitalSourceVOList
        }
        let isComplete = formInfo.value.data.assetUseDeptVOList.filter(
          (item) => item.useDeptName
        )
        if (!isComplete.length) {
          proxy.$message({
            type: 'warning',
            duration: 3500,
            message: '请填写使用部门',
            showClose: true,
          })
          return
        }
        if (Number(params.isFinanceAsset) == 0) {
          let financeAsset = [
            'originalAmount',
            'netAmount',
            'deprMonthsLimit',
            'monthsUsed',
            'deprPreparation',
            'sumDeprAmount',
            'deprMethodType',
            'deprMethodTypeValue',
            'deprConvention',
            'deprConventionValue',
            'postingDate',
            'monthDeprRate',
            'monthDeprAmount',
          ]
          for (let key in params) {
            financeAsset.forEach((item) => {
              if (key === item) {
                params[key] = ''
              }
            })
          }
        }
        if (Number(params.isMaintenance) == 0) {
          let maintenance = [
            'warrantyType',
            'warrantyTypeValue',
            'warrantyStatus',
            'warrantyStatusValue',
            'maintenanceProviderName',
            'maintenanceProviderId',
            'maintenanceContactsName',
            'maintenanceContactsId',
            'maintenancePhone',
            'hospitalMaintainerUserName',
            'hospitalMaintainerUserId',
            'hospitalMaintainerPhone',
            'warrantyStartDate',
            'warrantyEndDate',
            'maintenanceContract',
            'maintenanceDescription',
          ]

          for (let key in params) {
            maintenance.forEach((item) => {
              if (key === item) {
                params[key] = ''
              }
            })
          }
        }
        if (Number(params.isMetering) == 0) {
          let measurement = [
            'measurementName',
            'professionalClassification',
            'professionalClassificationValue',
            'isMandatoryInspection',
            'isMandatoryInspectionValue',
            'pinyinCode',
            'measurementRange',
            'accuracy',
            'verificationPeriod',
            'verificationType',
            'verificationTypeValue',
            'verificationUnit',
            'mainParameter',
            'verificationDate',
            'validityDate',
            'verificationResult',
            'verificationResultValue',
            'verificationCertificateNumber',
          ]

          for (let key in params) {
            measurement.forEach((item) => {
              if (key === item) {
                params[key] = ''
              }
            })
          }
        }
        // 删除 submitUser submitTime checkUser checkTime checkOpt  审批信息
        delete params.submitUser
        delete params.submitTime
        delete params.checkUser
        delete params.checkTime
        delete params.checkOpt
        let type
        let flowType = ''
        if (isSaveAndSubmit === true && proxy.$route.query.processInstanceId) {
          flowType = 'create'
        } else if (proxy.$route.query.processInstanceId) {
          flowType = 'update'
        }
        if (
          props.type === 'create' ||
          props.type === 'createSurplus' ||
          flowType === 'create'
        ) {
          let assetResourceObj =
            proxy.$refs.associatedSubcardTableForm.getAssociatedSubcardForm()
          if (!assetResourceObj.status) return
          params.assetResourceVOList = assetResourceObj.assetResourceVOList
          let assetSubcardTableData =
            proxy.$refs.assetSubcardTable.getassetSubcardData()
          params.relationAsset = assetSubcardTableData
          params.deviceTypeCategory = params.deviceTypeCategory || '-2'
          api = createAsset
          let paramsData = params
          console.log(1231212)
          if (isSaveAndSubmit === true) {
            if (proxy.$route.query.processInstanceId && !props.isCopy) {
              api = submitAssetCardOrder
            } else {
              api = createAssetAndSave
            }
            paramsData = {
              orderData: params,
              // flowTaskCommentDto和processDefinitionKey为审批流程需要传递的参数
              flowTaskCommentDto: { approvalType: 'submit' },
              processDefinitionKey: 'assetCard',
              processInstanceId: obj.processInstanceId,
              taskId: obj.taskId,
            }
          }
          type = 'create'
          if(!props.id && isBatch && (api == createAsset || api == createAssetAndSave)) {
            paramsData['countNum'] =  formBatchSaveInfo.data.countNum
          }
          proxy
            .$handleAPI(type, api, paramsData)
            .then((res) => {
              if (res.success) {
                showDialog.value = false
                emits('returnModify', false)
              }
            })
            .catch(() => {})

          // console.log(getAssociatedSubcardFormData)
          console.log(params)
        } else if (props.type === 'update' || flowType === 'update') {
          if (props.canModifyModule) {
            let assetResourceObj =
              proxy.$refs.associatedSubcardTableForm.getAssociatedSubcardForm()
            if (!assetResourceObj.status) return
            params.assetResourceVOList = assetResourceObj.assetResourceVOList
            params.deviceTypeCategory = params.deviceTypeCategory || '-2'
            let assetSubcardTableData =
              proxy.$refs.assetSubcardTable.getassetSubcardData()
            params.relationAsset = assetSubcardTableData
            updateRecording(params).then((res) => {
              if (res.success) {
                showDialog.value = false
                emits('returnModify', false)
              }
            })
          } else {
            let assetResourceObj =
              proxy.$refs.associatedSubcardTableForm.getAssociatedSubcardForm()
            if (!assetResourceObj.status) return
            params.assetResourceVOList = assetResourceObj.assetResourceVOList
            params.deviceTypeCategory = params.deviceTypeCategory || '-2'
            let assetSubcardTableData =
              proxy.$refs.assetSubcardTable.getassetSubcardData()
            params.relationAsset = assetSubcardTableData
            api = updateAsset
            type = 'update'
            proxy
              .$handleAPI(type, api, params)
              .then((res) => {
                if (res.success) {
                  showDialog.value = false
                  emits('returnModify', false)
                }
              })
              .catch(() => {})
          }
        } else if (props.type === 'buildCard') {
          //批量建卡
          let assetResourceObj =
            proxy.$refs.associatedSubcardTableForm.getAssociatedSubcardForm()
          if (!assetResourceObj.status) return
          params.assetResourceVOList = assetResourceObj.assetResourceVOList
          params.deviceTypeCategory = params.deviceTypeCategory || '-2'
          let obj = {}
          obj.coreAssetVO = { ...params }
          obj.orderDetail = props.buildCardData.map((item) => {
            return {
              orderId: item.id,
              qty: item.buildCardCalcQty,
            }
          })

          obj.productId = props.buildCardData[0].productId
          if (
            props.buildCardData[0].increaseType === 0 ||
            props.buildCardData[0].increaseType
          ) {
            //入库资产
            obj.orderSourceType = 66
          } else {
            //收货资产
            obj.orderSourceType = 15
          }
          api =
            isSaveAndSubmit === true
              ? checkBuildNumberForAssetCardAndSave
              : addByBatchBuildCard
          console.log(obj)
          api(obj)
            .then((res) => {
              if (res.success) {
                showDialog.value = false
                emits('returnModify', false)
              }
            })
            .catch(() => {})
        }
      })
      .catch((err) => {
        console.log(err)
        proxy.$message({
          message: '必填或非法校验未通过，请检查！',
          type: 'warning',
          duration: 3500,
          showClose: true,
        })
      })
  }
}

function showFinanceFieldListItem(show, nameValue) {
  let fieldList = formInfo.value.financeInfoFieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
}

function getDetails() {
  getAssetById(props.id).then((resp) => {
    if (resp && resp.success) {
      let data = resp.data
      if (resp.data.assetUseDeptVOList) {
        changeUseDeptNameFlag.value = true
      }
      if (
        data.assetCapitalSourceVOList &&
        data.assetCapitalSourceVOList.length
      ) {
        data.assetCapitalSourceVOList.forEach((item) => {
          if (item.capitalProjectList && item.capitalProjectList.length) {
            item.capitalProjectName = item.capitalProjectList
              .map((el) => el.assetCapitalProjectName)
              .toString()
          }
        })
      }

      formInfo.value.data = {
        ...data,
        deviceTypeCategory: data.deviceTypeCategory == '-2' ? '' : data.deviceTypeCategory,
        deprMonthsLimit: data.deprMonthsLimit % 12,
        deprYearsLimit: Math.floor(data.deprMonthsLimit / 12),
        unitId: data.unitId === -2 ? '' : data.unitId,
        assetType: data.assetType === -2 ? '' : data.assetType,
        deviceType: data.deviceType === -2 ? '' : data.deviceType,
        financialClassifyType:
          data.financialClassifyType === -2 ? '' : data.financialClassifyType,
        professionalClassification:
          data.professionalClassification === -2
            ? ''
            : data.professionalClassification,
        verificationResult:
          data.verificationResult === -2 ? '' : data.verificationResult,
        verificationType:
          data.verificationType === -2 ? '' : data.verificationType,
        assetUseDeptVOList: data.assetUseDeptVOList
          ? data.assetUseDeptVOList
          : [{ useDeptName: '' }],
        assetCapitalSourceVOList: data.assetCapitalSourceVOList
          ? data.assetCapitalSourceVOList
          : [
              {
                code: '',
                amount:
                  props.canModifyModule === 'noFinanceAsset'
                    ? 0
                    : data.primitiveOriginalAmount,
              },
            ],
        netAmount:
          data.netAmount ||
          utils.Subtr(
            utils.Subtr(
              utils.Subtr(data.originalAmount || 0, data.residualAmount || 0),
              data.sumDeprAmount || 0
            ),
            data.deprPreparation || 0
          ),
        postingDate:
          data.postingDate || moment(new Date()).format('YYYY-MM-DD'),
      }
      formInfo.value.data.fileUrlList = resp.data.fileUrlList || []
      formInfo.value.data.assetFileUrlList =
        resp.data.assetFileUrlList || undefined
      if (props.canModifyModule != 'noFinanceAsset') {
        isShowAddEquipment.value = true
      }
      if (
        formInfo.value.data.orderSourceId &&
        formInfo.value.data.orderSourceId !== -2 &&
        props.type !== 'create'
      ) {
        //通过资产入库、收货新增的资产
        isShowAddEquipment.value = false
        formInfo.value.baseInfoFieldList.forEach((item) => {
          if (
            item.value === 'useStatus' ||
            item.value === 'assetName' ||
            item.value === 'primitiveOriginalAmount'
          ) {
            item.disabled = true
          }
        })
        if (formInfo.value.data.avaiableEditSupplier) {
          //资产入库无供应商的标志，true可以修改供应商，没得则不可修改供应商
          formInfo.value.baseInfoFieldList.forEach((item) => {
            if (item.value === 'temporaryPurch') {
              item.disabled = false
            }
          })
        } else {
          formInfo.value.baseInfoFieldList.forEach((item) => {
            if (item.value === 'temporaryPurch') {
              item.disabled = true
            }
          })
        }
      }
      if (props.canModifyModule === 'noFinanceAsset') {
        if (formInfo.value.data.assetStatus === 3) {
          showFieldListItem(true, 'depotName')
          // showFieldListItem(false, 'useDeptName')
        } else {
          showFieldListItem(false, 'depotName')
          // showFieldListItem(true, 'useDeptName')
        }
      }

      proxy.$nextTick(() => {
        assetCapitalSourceTableForm.value.clearValidate()
      })
      if (props.type === 'create') {
        //复制并新增type:'create'&&this.id同时存在
        delete formInfo.value.data.assetCode
        delete formInfo.value.data.id
        delete formInfo.value.data.status
        delete formInfo.value.data.statusValue
        delete formInfo.value.data.orderSourceId
        delete formInfo.value.data.orderSourceNo
        delete formInfo.value.data.orderSourceType
        delete formInfo.value.data.isLocked
        delete formInfo.value.data.isLockedValue
        delete formInfo.value.data.lockedReason

        if (formInfo.value.data.depotName) {
          formInfo.value.data['useStatus'] = 1
        }
        //  else if (formInfo.value.data.useDeptName) {
        //   formInfo.value.data['useStatus'] = 2
        // }
        formInfo.value.data['remark'] = ''
      } else {
        if (
          formInfo.value.data.orderSourceId &&
          formInfo.value.data.orderSourceId !== -2
        ) {
          formInfo.value.baseInfoFieldList.forEach((item) => {
            if (item.value === 'useStatus') {
              item.disabled = true
            }
          })
        }
      }
    }
  })
}
function getStatus() {
  getCoreCodeStatus({ codeType: '7' }).then((res) => {
    isShowBatchSave.value = res.data && !props.id
    showFieldListItem(!res.data, 'assetCode')
  })
  // getSequence({ code: 'asset' }).then((res) => {
      // 启用 不显示
      // showFieldListItem(!res.data, 'assetCode')
  // })
}
function showFieldListItem(show, nameValue) {
  let fieldList = formInfo.value.baseInfoFieldList
  fieldList.forEach((item) => {
    if (nameValue === item.value) {
      item.show = show
    }
  })
  console.log(fieldList)
}
// 名称不要做改变，在流程引擎中需要通过refs进行调用
defineExpose({
  save,
  saveAndSubmit,
})
</script>

<style scoped>
.i-more-disabled {
  cursor: not-allowed;
}
.i-more {
  background-color: #ffffff;
  cursor: pointer;
  height: 26px;
}

:deep(.el-upload-list) {
  width: 158px;
  height: 172px;
}
:deep(.ele-gallery .el-upload-list--picture-card .el-upload-list__item) {
  height: 150px;
}
</style>
